import json
d={"name":"孫悟空","age":18,"gender":"MALE"}
f=open("d:/test.json","w",encoding='utf-8')
json.dump(d,f)
f.close()為什么寫入的文件中不是漢字,而是unicode?{"name": "u5b59u609fu7a7a", "age": 18, "gender": "MALE"}
1 回答

拉丁的傳說
TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊
json.dump(d,f,ensure_ascii=False)
If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped. If ensure_ascii is false, these characters will be output as-is.
添加回答
舉報(bào)
0/150
提交
取消