码迷,mamicode.com
首页 > 编程语言 > 详细

Python中json一点小知识

时间:2018-08-18 10:26:30      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:open   ensure   with   class   pytho   int   序列化   coding   ascii   

import json
dic={
    "name":"杨林"
}

ret=json.dumps(dic,ensure_ascii=False) #因为json.dumps 序列化时对中文默认使用的ascii编码.想输出真正的中文需要指定ensure_ascii=False
print(ret)
with open("j.son","w",encoding="utf-8") as f:  #提前制定encoding
    f.write(ret)

#print输出{"name": "杨林"},j.son也输出{"name": "杨林"}

 

Python中json一点小知识

标签:open   ensure   with   class   pytho   int   序列化   coding   ascii   

原文地址:https://www.cnblogs.com/hbxZJ/p/9495953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!