简体   繁体   English

如何从 Node-red 中的嵌套 JSON 有效负载中提取“temp”的值?

[英]How do I extract the value of 'temp' from a nested JSON payload in Node-red?

{"rssi":-46,"message":"{\"temp\":55,\"hum\":88,\"moist\":50}"}

In the above payload, I can extract the value of rssi using the following code in Node-red.在上面的有效载荷中,我可以使用 Node-red 中的以下代码提取rssi的值。

p = JSON.parse(msg.payload);
node.log(typeof p);
msg.payload = p.rssi;
return msg;

But how do I extract the value of temp from this.但是我如何从中提取temp的值。

There is a colon missing in the source json.源 json 中缺少一个冒号。 It should be它应该是

{"rssi":-46,"snr":{"temp":55,"hum":88,"moist":55}"} {"rssi":-46,"snr":{"temp":55,"hum":88,"moist":55}"}

Like @Andreas mentioned, after first line its all about accessing the object "p".就像@Andreas 提到的那样,在第一行之后,它的全部内容都是关于访问 object “p”。

You should be able to access the temp using您应该能够使用

msg.payload=p.snr.temp;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM