总有一些坑,需要填
★ python json.dump中文乱码问题
with open(os.path.join(file, 'vocab.json'), 'w') as f:
json.dump(vocab, f)
修改:
with open(os.path.join(file, 'vocab.json'), 'w', encoding='utf-8') as f:
json.dump(vocab, f,ensure_ascii=False)
参考:https://www.cnblogs.com/lxyykl001/p/11287456.html
★ python读文件时出现:UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position xx: 解决方案
with open(filename, 'r') as f:
data = json.load(f)
return data
修改:
with open(filename, 'r', encoding='utf-8') as f:
data = json.load(f)
return data
参考:https://www.cnblogs.com/blogpro/p/11343791.html