在您尝试访问其字段之前,应将您显示的 JSON 字符串转换为 Javascript 对象。要做到这一点就像将 arduino 输出连接到“JSON”节点一样简单,该节点会为您进行转换(如果字符串是 not 有效的 JSON,则会引发错误)。
如果您想查看 msg 对象的结构,请将 JSON 节点的输出连接到调试节点。例如,如果您只想将 msg.payload 替换为温度值,您也可以将其连接到“更改”节点。您不需要函数节点中的任何自定义 javascript 代码来执行类似的简单更改。
[{"id":"1a79abfe.b8abb4","type":"inject","z":"58c8eb7a.5496c4","name":"发送输出","topic":"iot-2 /type/Arduino-tempsensor/id/FFFFFFFFFFFF/evt/status/fmt/json","payload":"true","payloadType":"bool","repeat":"","crontab":"", "once":false,"onceDelay":0.1,"x":170,"y":2740,"wires":[["9fc678fb.ae18e8"]]},{"id":"69e91778.e0c6e8", "type":"json","z":"58c8eb7a.5496c4","name":"","property":"payload","action":"","pretty":false,"x": 390,"y":2800,"wires":[["d066800f.60a9b","cf991eb1.f2a1a"]]},{"id":"9d8d7da2.2a7da","type":"debug","z ":"58c8eb7a.5496c4","name":"msg string","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload"," x":610,"y":2740,"wires":[]},{"id":"9fc678fb.ae18e8","type":"template","z":"58c8eb7a.5496c4","name ":"arduino string","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\n \"d \": {\n \"myName\": \"Arduino CF\",\n \"cmdmsg\": \"每周\",\n \"tempr\": -3\n }\n}" ,"输出":"str","x":360,"y":2740, "电线":[["69e91778.e0c6e8","9d8d7da2.2a7da"]]},{"id":"d066800f.60a9b","type":"change","z":"58c8eb7a.5496c4", "name":"extract tempr","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.d.tempr" ,"tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450 ,"y":2860,"wires":[["af730d72.2995a"]]},{"id":"af730d72.2995a","type":"debug","z":"58c8eb7a.5496c4" ,"名称":"tempr","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y" :2860,"wires":[]},{"id":"cf991eb1.f2a1a","type":"debug","z":"58c8eb7a.5496c4","name":"msg object","活动":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":2800,"wires":[]} ]