json - 带有 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
解决方案
我发现自己也遇到了这个错误。不要附加句点,而是尝试以下操作:result['Data']
访问列表并result['Data']['Traffic']
获取值 6231。
推荐阅读
- r - “标记”ggplot2中的刻度线?
- python - 将日期时间对象插入 BigQuery 时,Google Cloud 函数崩溃
- ruby-on-rails - 如何建立这种多态关系?
- c++ - 使用宏来摆脱依赖的模板关键字是个好主意吗?
- python - 无法从 xpath 获取价值
- python - Git 最佳实践:如何构建一个大型应用程序所需的多个 python 模块
- function - 使用功能 swiftUI 将视图添加到 contentView 不起作用
- multipartform-data - 如何解释缺少 CRLF 的多部分?
- azure - 将 Function App 连接到特定设备?
- css - 下拉菜单高度动画