python中的JSON解析给出了错误 - UnicodeDecodeError

时间:2014-02-17 08:09:43

标签: python json

我的JSON文件是

{ "results": [ 
{ "ID": "63768E9B-1D66-486A-BCDD-D3991EAFBE94", 
"Dt": "2013-08-03T13:01:26.901Z", 
"Dt_u": "2013-08-03T13:01:26.901Z", 
"obj": "enppXhI7TS" 
}, 
{ 
"ID": "63768E9B-1D66-486A-BCDD-D3991EAFBE94", 
"Dt": "2013-08-03T16:17:33.280Z",
"Dt_u": "2013-08-03T16:17:33.280Z",
"obj": "79J5z6y2UR" 
}, 
{ 
"ID": "F8B1B9FB-7BCD-47DF-89BD-241440BB6270",
"Dt": "2013-08-06T00:23:43.562Z", 
"obj": "Xf75BFtx4O",
"gender": 2,
"language": "en"
}]}

文件中还有更多条目

我的python代码如下

import json
from pprint import pprint


json_data=open('data.json','r')

data = json.load(json_data)
jsondata = data["results"]

for item in jsondata:
name = item.get("ID")
json_data.close()

当我尝试运行该文件时,它会出现以下错误

Traceback (most recent call last):
  File "E:\test.py", line 7, in <module>
    data = json.load(json_data)
  File "C:\python27\lib\json\__init__.py", line 290, in load
    **kw)
  File "C:\python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\python27\lib\json\decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\python27\lib\json\decoder.py", line 381, in raw_decode
   obj, end = self.scan_once(s, idx)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc2 in position 2: invalid    continuation byte
[Finished in 0.2s with exit code 1]

有人可以帮助我并告诉我该如何解决它?

0 个答案:

没有答案