Json.loads抛出ValueError

时间:2013-08-16 01:28:56

标签: python json

Python 2.6.6 而我正在做的就是从zmq和json.loads(消息)接收消息。 对不起json所有的混乱,因为它是

{"mouhter_id":"one_keert","header":{"header_version":"1","message_type":"one_keert","session_id":"428c0ebd497b9dfcc3170da0d1e0628e","timestamp":1376616699,"src_path":"*/dc/occ1/bell000/lcd_one_mtmt/26866","dst_path":"*/dc/lkjhgvd/lkjhgvd/fegtault/24068"},"payload":{"destHardwareId":"","command":{"id":"bmclmc1","params":{"keylen":"396","key":"AAAAIM0XlJxAEiX6t1KSyuQh+gCnP1Jmu3lkTZvxhiOUogyMAAABDC0tLS0tQkVHSU4gUFVCTElDIEtFWS0tLS0tCk1JR2JNQkFHQnlxR1NNNDlBZ0VHQlN1QkJBQWpBNEdHQUFRQjAxaTZkOG5xVTBnQVBIdHhFMDZqNEI0UDF4TXoKVTVYYy83RnZCVzBtTFI3WlQxRTRxUmw3VEx0OVcwSi85OU5XRzF3NU14Um1oK2dubEJxTTFkNytadU1BNU1NdgpFbmNHcmFpNU1UcHo3elE0cm9CQWZFOVA0czFvM0dRaThSRlVSbFJMdWl2Ym1jempkcVdCYVlEUjNCUU9IOU96ClRWOHFhUnpCN3l0T1NnS09yZzA9Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQoAAABAg7od/LedQJ8MEBvKQjcBWM2ObdIeSDd/2VygDn0XFwBgUpYiWgum7FE8O51E0Xv3/R6ibvgSPFblqHqLDBNzOgAAAAAAAAAAAAAAAAAAAAAAAAAA"}}}}

我遵循JSON并在python中尝试加载它以便我可以提取数据。

{
   "e_id": "1231231",
   "header": {
              "h_version": "1",
              "m_type": "abc",
              "s_id": "ffsfsd",
              "timestamp": 1376614509,
              "s_path": "*/dc/s1/De620/cpmgmt/25804",
              "d_path": "*/dc/sfer/sfer/kelt/23642"
              },
"payload": {
"dereId": "",
"cond":       {
              "id": "srcstg1",
              "pams": {
                     "keen": "396",
                     "ke":                               "AAAAICZJsxIYABq3JXFRJ7ouZtoLDOLIJBnrw03uASQTiK+nAAABDC0tLS0tQkVHSU4gUFVCTElDIEtFWS0tLS0tCk1JR2JNQkFHQnlxR1NNNDlBZ0VHQlN1QkJBQWpBNEdHQUFRQkR2SEZLNVZZdUg3ZUFMRitLeWhLbWl0TEdEMzAKZmJOakNHYkVNRW1Geld4cFgzZXJ0RjhKSjdjMWZ6cFRhekJGRkpDNW5vR3FycWl2M3VGbGNuMitjUUlCUC9LaQo4V0h4ZVNBVkQ3R2lNTXJHMEVGYTBrOWNucnd5MEtWeU93MEVYcmwyQUNJcXg5enZBV3NLeERhUjRlRzRZVi9jCjB2cVlKcEh1OXNMbE9jWDJJVW89Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQoAAABA+T4YOvY1ynTIlAUn8xI+/0c+2EAPRFF1uHx8jBP7uuNkb/wnRZl0hJWx6NAOd0kHuh2RdIXXMhXChaEWRNxq6wAAAAAAAAAAAAAAAAAAAAAAAAAA"
                     }
               }
           }
}

它给我发了以下错误:

raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 904 - line 1 column 905 (char 904 - 905)

我已经使用jsonlint检查文件的有效性,似乎通过了验证。但是我仍然收到此错误? 已从字符串中删除所有新行和制表符。 这里有什么遗失?

1 个答案:

答案 0 :(得分:1)

在json字符串的末尾有一个空字符,我从c ++客户端获取它,所以只删除了那个空字符,现在一切正常。