代码之家  ›  专栏  ›  技术社区  ›  Sonu Kumar

Alexa with lambda函数解析json错误

  •  0
  • Sonu Kumar  · 技术社区  · 6 年前

    用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
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   user10124766    6 年前

    我发现自己也犯了这个错误。不要附加句点,请尝试以下操作: result['Data'] 访问列表和 result['Data']['Traffic'] 得到6231的值。