为什么Python的json.dump保存的是unicode?

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"}

clipboard.png

阅读 2.9k
1 个回答

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.
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏