json读写

import json

l = [1,2,'abc',{'name':'bob','age':13}]
print(json.dumps(l))

d = dict(b=None,a=5,c='abc')
print(json.dumps(d, separators=[',',':']))  # 设置分隔符


# 按key值排序
print(json.dumps(d, sort_keys=True))


l2 = json.loads('{"b":"x","a":5,"c":"abc"}')
print(l2)




with open('','wb') as f:
    json.dump(l,f)

 

posted @ 2019-03-03 19:49  Ray_chen  阅读(166)  评论(0编辑  收藏  举报