Python解析文件乱码问题
遇到此问题一般情况需要Open文件时指定编码即可:
方式一
with open('/..../2.1.docx', 'r', encoding='utf8') as fr:
data = fr.read()
print(data)
方式二
出现以下错误时,
raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-sig)",
json.decoder.JSONDecodeError: Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)
调整:
with open(file_path, 'r', encoding='utf8') as f:
json_obj = json.loads(f.read())