open('*.json') 给出 "UnicodeDecodeError"
open('*.json') gives "UnicodeDecodeError"
我正在尝试使用以下代码将 .json 文件导入为字典:
import json
with open('StreamingHistory0.json') as json_file:
history = json.load(json_file)
但是,我不断收到以下错误:
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 97181: character maps to <undefined>
此错误的原因是什么,是否有合适的修复方法?
很可能是编码错误。尝试
with open('StreamingHistory0.json', encoding='utf-8')
我正在尝试使用以下代码将 .json 文件导入为字典:
import json
with open('StreamingHistory0.json') as json_file:
history = json.load(json_file)
但是,我不断收到以下错误:
File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 97181: character maps to <undefined>
此错误的原因是什么,是否有合适的修复方法?
很可能是编码错误。尝试
with open('StreamingHistory0.json', encoding='utf-8')