AWS Lambda Javascript JSON 对象未定义

AWS Lambda Javascript JSON object undefined

我的 lambda 函数被 IoT 规则调用(JSON 中的 MQTT 消息)。我只是想记录值,顶级点字段工作正常,但 JSON 中的嵌套对象被视为 "undefined"。我尝试 JSON.stringify 这些但没有成功。有什么想法吗?

'use strict';
console.log('Loading function');
exports.handler = (event, context, callback) => {
  console.log('Received event:', JSON.stringify(event, null, 2)); // Complete message
  console.log('Received event.ApiVersion:',event.ApiVersion);
  console.log('Received event.CollectionID:',event.CollectionId);
  console.log('Received event.TagData.Time:',event.TagData.Time); //undefined

  var TimeObj = {}; 
  TimeObj = event.TagData.Time;
  console.log('Received event TimeObj:',TimeObj); //undefined
};

以下是云监视日志/结果:

Loading function
Received event:
{
 "FormatId": "TagValues",
 "ApiVersion": 1,
 "CollectionId": 2,
 "TagData": [
     {
         "Time": "2017-09-02T11:06:35.917000+02:00",
         "Values": {
             "var1": 16777216,
             "var2": 7534
         }
     }
 ]
}
Received event.ApiVersion: 1
Received event.CollectionID: 2
Received event.TagData.Time: undefined
Received event TimeObj: undefined

TagData 是数组而不是对象,所以 TagData.Time returns undefined.

改变

event.TagData.Time;

event.TagData[0].Time;