首页 > 解决方案 > 带有 lambda 函数的 Alexa 解析 json 错误

问题描述

用lambda函数开发Alexa,json解析错误

如何解析json响应

{
"Status": true,
"Error": "",
"Data": [
    {
        "Traffic": 6231
    }
],
"Message": null
}

我的代码

result.Data[0].Traffic

错误 :

    START RequestId: 4578b114-9bba-11e8-94a6-611a9b05be3f Version: $LATEST
2018-08-09T09:54:57.434Z    4578b114-9bba-11e8-94a6-611a9b05be3f    Warning: Application ID is not set
2018-08-09T09:54:57.435Z    4578b114-9bba-11e8-94a6-611a9b05be3f    traffic Plaza: sutpl1
2018-08-09T09:54:58.028Z    4578b114-9bba-11e8-94a6-611a9b05be3f    TypeError: Cannot read property '0' of undefined
    at IncomingMessage.res.on (/var/task/index.js:487:32)
    at emitNone (events.js:91:20)
    at IncomingMessage.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9)
END RequestId: 4578b114-9bba-11e8-94a6-611a9b05be3f
REPORT RequestId: 4578b114-9bba-11e8-94a6-611a9b05be3f  Duration: 654.57 ms Billed Duration: 700 ms     Memory Size: 576 MB Max Memory Used: 34 MB  
RequestId: 4578b114-9bba-11e8-94a6-611a9b05be3f Process exited before completing request

标签: jsonnode.jslambdaalexa-skill

解决方案


我发现自己也遇到了这个错误。不要附加句点,而是尝试以下操作:result['Data']访问列表并result['Data']['Traffic']获取值 6231。


推荐阅读