从 json 红色节点中提取值
extract values from json red node
"{"values":[{"key": "id", "value": 171},{"key": "counter", "value": 0},{"key": "temperature", "value": 2561},{"key": "x_axis", "value": -223},{"key": "y_axis", "value": -256},{"key": "z_axis", "value": 246},{"key": "battery", "value": 2817}]}"
我有一个设备 (zolertia z1) 使用 MQTT 发送 json 数据,我正在使用 node-RED 中的函数来提取值,但我的代码一直出错
return {values: msg.values.temperature};
错误:
function : (error)
"TypeError: Cannot read property 'temperature' of undefined"
MQTT 节点的输出是字符串而不是 JSON 对象。
运行 通过 JSON 节点的输出将字符串转换为 JSON 对象,然后再将其传递给您的函数节点。
此外,对象将被设置为 msg.payload.values
而不是 msg.values
"{"values":[{"key": "id", "value": 171},{"key": "counter", "value": 0},{"key": "temperature", "value": 2561},{"key": "x_axis", "value": -223},{"key": "y_axis", "value": -256},{"key": "z_axis", "value": 246},{"key": "battery", "value": 2817}]}"
我有一个设备 (zolertia z1) 使用 MQTT 发送 json 数据,我正在使用 node-RED 中的函数来提取值,但我的代码一直出错
return {values: msg.values.temperature};
错误:
function : (error)
"TypeError: Cannot read property 'temperature' of undefined"
MQTT 节点的输出是字符串而不是 JSON 对象。
运行 通过 JSON 节点的输出将字符串转换为 JSON 对象,然后再将其传递给您的函数节点。
此外,对象将被设置为 msg.payload.values
而不是 msg.values