当我运行时:
import json, sys
with open('/Users/mac/Desktop/export-2017-04-28-0235-25014395ac.json', 'r') as json_data:
d = json.load(json_data)
print(d)
它返回一个错误,我不确定该怎么想。我完成了我的研究,我不确定我明白了什么是错的。如果有人可以帮助我,那就太棒了。
这是错误:
Traceback (most recent call last):
File "/Users/mac/Desktop/untitled.py", line 4, in <module>
d = json.load(json_data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 296, in load
return loads(fp.read(),
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 39966: ordinal not in range(128)
[Finished in 0.5s with exit code 1]
[shell_cmd: python3 -OO -u "/Users/mac/Desktop/untitled.py"]
[dir: /Users/mac/Desktop]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
答案 0 :(得分:4)
JSON希望您进行解码。 99%的时间utf-8
完成工作。
import json, sys
with open('/Users/mac/Desktop/export-2017-04-28-0235-25014395ac.json',
'r', encoding='utf-8') as json_data:
d = json.load(json_data)
print(d)