pycharm 打开的json文件
通过代码读取中文文件
?
保存中文的json文件:
import json
with open('garbage_classification.json',encoding='utf-8-sig',mode='r') as f:
data = json.load(f)
# print(data) {'0': '可回收物_金属食品罐', '1': '其他垃圾_PE塑料袋', '2': '其他垃圾_污损塑料'...}
data = json.dumps(data,indent=4,ensure_ascii=False)
with open('./classes_indices.json',encoding='utf-8',mode='w') as f:
f.write(data)
结果:
?