node-RED json object - how to extract json values

浪尽此生 提交于 2019-12-11 02:38:56

问题


In node-RED, I used 'batcher' node to bring 2 Humidity readings together in a msg, which I want in a json format, to use it downstream, one for inside, there other in a quad.

The constructed msg object now looks like this:

{ "topic": "Hum", "payload": [ { "inside": 29 }, { "quad": 54 } ] }

I am trying to get to elements in this object, with:

msg.payload.inside

But it is not working, how can I get to for instance the inside humidity ?


回答1:


The payload property of that object is an Array that contains two elements.

If you want to access the value of an object inside that array, you need to index into it.

Arrays are indexed from 0 - so you want to use msg.payload[0].inside

Note that this is standard JavaScript and not specific to Node-RED.



来源:https://stackoverflow.com/questions/41026642/node-red-json-object-how-to-extract-json-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!