【发布时间】:2018-08-09 10:01:18
【问题描述】:
用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
【问题讨论】:
-
尝试这样的事情,因为如果您查看错误,您会遇到类型错误: if(result.Data.length > 0 && result.Data[0].Traffic) { result.Data [0].交通; }
标签: json node.js lambda alexa-skill