如何在python中解析多个json数据?

时间:2017-05-12 10:31:41

标签: python json

我的设备将发送如下的json数据:

[{"channel":924125000, "sf":10, "time":"2017-05-11T16:56:15", "gwip":"192.168.1.125", "gwid":"00004c4978dbf5b4", "repeater":"00000000ffffffff", "systype":5, "rssi":-108.0, "snr":17.0, "snr_max":23.3, "snr_min":10.8, "macAddr":"00000000000000c3", "data":"4702483016331210179183", "frameCnt":1, "fport":2}]

但有时我收到了多个json数据(两个或更多):

[{"channel":924125000, "sf":10, "time":"2017-05-11T16:56:15", "gwip":"192.168.1.125", "gwid":"00001c497b48dbf5", "repeater":"00000000ffffffff", "systype":5, "rssi":-108.0, "snr":17.0, "snr_max":23.3, "snr_min":10.8, "macAddr":"00000000050100e8", "data":"4702483016331210179183", "frameCnt":1, "fport":2}],[{"channel":924125000, "sf":10, "time":"2017-05-11T16:56:15", "gwip":"192.168.1.125", "gwid":"00001c497b48dbf5", "repeater":"00000000ffffffff", "systype":5, "rssi":-108.0, "snr":17.0, "snr_max":23.3, "snr_min":10.8, "macAddr":"00000000050100e8", "data":"4702483016331210179183", "frameCnt":1, "fport":2}]

当我解析多个json数据时

json_Dict = json.loads(jsonData)

然后

File "/usr/lib/python2.7/json/decoder.py", line 369, in decode raise ValueError(errmsg("Extra data", s, end, len(s))) ValueError: Extra data: line 1 column 303 - line 1 column 1818 (char 302 - 1817)

如何解析每个多个json数据?

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

将其粘贴到JSONLINT

等工具中

你得到:

  

错误:第17行的解析错误:   ......“:1,”fport“:2}],[{”频道“:924   --------------------- ^   期待'EOF',得到','

这是导致错误的原因。这不是有效 JSON。 正确的结构类似[[...],[...]]。您有[...],[...],这是不正确的。