AWS Lambda Javascript JSON对象未定义

编程入门 行业动态 更新时间:2024-10-21 04:04:39
本文介绍了AWS Lambda Javascript JSON对象未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的lambda函数由IoT规则(JSON中的MQTT消息)调用.我只是尝试记录这些值,并且顶级点字段可以正常工作,但JSON中的嵌套对象被视为未定义".我试图对它们进行JSON.stringify,但没有成功.有什么想法吗?

My lambda function is called with by an IoT rule (MQTT message in JSON). I am simply trying to log the values, and the top level dot fields work fine, but nested objects in the JSON are seen as "undefined". I tried to JSON.stringify these with no success. Any ideas?

'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 };

这是云监视日志/结果:

Here are the cloud watch logs / results:

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返回undefined.

TagData is an array and not an object, so TagData.Time returns undefined.

更改

event.TagData.Time;

收件人

event.TagData[0].Time;

更多推荐

AWS Lambda Javascript JSON对象未定义

本文发布于:2023-11-28 06:59:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   未定义   Lambda   AWS   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!