Support Questions
Find answers, ask questions, and share your expertise

How do we solve this?

New Contributor
  • 从MQTT接收到的数据,要读入json数组

  • Spoiler
    {"device_name":"Device37","device_id":"GanghuaLianXian","date":"2021-09-24 17:45:44","sensor":[{"sensor_id":"Data05_37_alarm","value ":"0"},{"sensor_id":"Data06_37_alarm","value":"0"},{"sensor_id":"Data07_37_alarm","value":"0"},
    {"sensor_id":"Data08_37_alarm ","value":"0"},{"sensor_id":"Data09_37_alarm","value":"0"},{"sensor_id":"Data10_37_alarm","value":"0"},{"sensor_id ":"Data11_37_alarm","value":"0"},
    {"sensor_id":"Data12_37_alarm","value":"0"},{"sensor_id":"Data13_37_alarm","value":"0"},{"sensor_id":"Data14_37_alarm","value":"0"},{"sensor_id":"Data15_37_alarm", "value":"0"},
    {"sensor_id":"Data16_37_alarm","value":"0"},{"sensor_id":"Data17_37_alarm","value":"0"},{"sensor_id": " Data18_37_alarm","value":"0"},{"sensor_id":"Data19_37_alarm","value":"0"},"0"},Data15_37_alarm","value":"0"}, {"sensor_id":"Data16_37_alarm","value":"0"},{"sensor_id":"Data17_37_alarm","value":"0"},{" sensor_id":"Data18_37_alarm","value":"0"},{"sensor_id":"Data19_37_alarm","value":"0"},"0"},Data15_37_alarm","value":"0"}, {"sensor_id":"Data16_37_alarm","value":"0"},{"sensor_id":"Data17_37_alarm","value":"0"},{" sensor_id":"Data18_37_alarm","value":"0"},{"sensor_id":"Data19_37_alarm","value":"0"},"0"},{"sensor_id":"Data16_37_alarm","value":"0"},{"sensor_id":"Data17_37_alarm","value":"0"},{"sensor_id":"Data18_37_alarm", "value":" 0"},{"sensor_id":"Data19_37_alarm","value":"0"},"0"}, {"sensor_id":"Data16_37_alarm","value":"0"},{"sensor_id": "Data17_37_alarm","value":"0"},{"sensor_id":"Data18_37_alarm", "value":"0"},{"sensor_id":"Data19_37_alarm","value":"0"},
    { "sensor_id":"Data20_37_alarm","value":"0"},{"sensor_id":"Data21_37_alarm","value":"0"},{"sensor_id":"Data22_37_alarm","value":"0"},{"sensor_id":"Data23_37_alarm","value":"0"},
    {"sensor_id": "Data24_37_alarm","value":"0"},{"sensor_id":"Data25_37_alarm","value":"0"},{"sensor_id":"Data26_37_alarm","value":"1"},{ "sensor_id":"Data27_37","value":"1"},
    {"sensor_id":"Data28_37","value":"0"},sensor_id":"Data24_37_alarm","value":"0"},{"sensor_id":"Data25_37_alarm","value":"0"},{"sensor_id":"Data26_37_alarm","value":"1" },{"sensor_id":"Data27_37","value":"1"}, {"sensor_id":"Data28_37","value":"0"},sensor_id":"Data24_37_alarm","value":"0"},{"sensor_id":"Data25_37_alarm","value":"0"},{"sensor_id":"Data26_37_alarm","value":"1" },{"sensor_id":"Data27_37","value":"1"}, {"sensor_id":"Data28_37","value":"0"},
    {"sensor_id":"Data29_37","value":"0"},{"sensor_id":"Data30_37_alarm","value":"0"},{"sensor_id":"Data31_37_state","value":" 0"},
    {"sensor_id":"Data32_37_state"," value":"1"},{"sensor_id":"Data01_37_count","value":"9776"},{"sensor_id":"Data02_37_count"," value":"9777"}],
    "状态":1 }Data02_37_count","value":" 9777"}], "状态":1}Data02_37_count","value":" 9777"}], "状态" :1}
  • EvaluateJsonPath 如何获取JSON数组

我正在使用 EvaluateJsonPath 并且无法读取传感器数据cn-programmer_0-1632796511690.png

  • error

cn-programmer_0-1632796668404.png

 

 

1 ACCEPTED SOLUTION

Expert Contributor

I think the problem is that you are trying to evaluate path on a list of sensors:

sensor":[{"sensor_id":"Data05_37_alarm","value ":"0"},{"sensor_id":"Data06_37_alarm","value":"0"}....

you probably need to flatten json first and if you are trying to get each sensor information then you need to do splitjson and then you can do evaluatejsonpath. Hope that helps.

View solution in original post

2 REPLIES 2

Expert Contributor

I think the problem is that you are trying to evaluate path on a list of sensors:

sensor":[{"sensor_id":"Data05_37_alarm","value ":"0"},{"sensor_id":"Data06_37_alarm","value":"0"}....

you probably need to flatten json first and if you are trying to get each sensor information then you need to do splitjson and then you can do evaluatejsonpath. Hope that helps.

New Contributor

First of all, thank you for your reply. I will try your method

; ;