如果json.dumps
中不设置ensure_ascii=False
的话,写入结果为unicode编码。
import json
data = {
"name": "xaioming",
"age": 18,
"昵称": "狗蛋"
}
with open("./data/data.json", "w", encoding="utf-8") as f:
f.write(json.dumps(data, ensure_ascii=False))
上述代码的输出结果为:
猜你喜欢:👇🏻
⭐【Python】with open 打开文件的不同方式
⭐【Python】多次写入excel的不同sheet
⭐【Java】读取本地Json文件