python实现将json数据以json格式写入txt文件

json.dumps中indent参数是设置json缩进量的

举例:

tmp = {
"aaa" : "111",
"bbb" : '222'
}
import json

with open("tmp.txt", "w") as fp:
fp.write(json.dumps(tmp,indent=4))


打开tmp.txt查看效果

 


posted @ 2018-11-09 12:51  致橡树的你  阅读(12350)  评论(0编辑  收藏  举报