为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

有只小跳蛙 2019-01-30 10:53:14
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贡献1789条经验 获得超8个赞

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.


查看完整回答
反对 回复 2019-01-30
  • 1 回答
  • 0 关注
  • 1052 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号