首页 > 解决方案 > 用nodered提取json

问题描述

我想在带有节点红色的消息中提取 json 部分

我收到红色节点的消息,但无法提取消息的数据示例:

POST / HTTP/1.1

Host: xxx.xx.xxx.5:9000

User-Agent: libcurl-agent/1.0

Content-type: application/json

Accept: application/json

Content-Length: 526   
   {
   "timestamp": 1571997083,
   "data": {
      "temperature": 20.613545532227,
      "humidity": 61.3828125,
      "battery": 3.47
   },
   "frame": "814962xxxx16a1dc5",
   "gatewayID": "AA555Axxxx0xx964",
   "othersGW": [],
   "clientID": "xxxx",
   "DevAddr": "011xxxxb",
   "DevEUI": "8cf9xxx000000xxx",
   "sensorInstallId": "8cf95xxx0000xxxx",
   "loraPort": 8,
   "fcnt": 1607,
   "rxpk": {
      "tmst": 2380181019,
      "time": "2019-10-25T09:51:23.472998Z",
      "chan": 0,
      "rfch": 0,
      "freq": 867.1,
      "stat": 1,
      "modu": "LORA",
      "datr": "SF7BW125",
      "codr": "4/5",
      "lsnr": 9,
      "rssi": -72,
      "size": 22,
      "data": "xxxxxxxxxxxxxxxx/YxWg=="
   }
}

所以我想要温度等数据......我不知道我必须使用的节点

非常感谢

标签: jsonnode-red

解决方案


从评论中更好地了解您正在尝试做什么。

使用TCP-in节点可能不是正确的方法。HTTP-in使用/节点会做得更好,HTTP-out因为它们将处理所有 HTTP 标头并向客户端发送正确的响应,以便关闭连接。

HTTP-in节点采用一个路径,例如,该路径/input将附加到 Node-RED URL 中,给出类似http://localhost:1880/input. 它还需要一个 HTTP 动词,在这种情况下是POST. 您可以在此处的 Node-RED 食谱中找到更多详细信息和大量示例。

您需要更新客户端以指向正确的路径和端口。


推荐阅读