json.dumps
dicts = [{1: 2, "name": "age", 'hehe': {"name": "chang"}}]
strs = json.dumps(dicts)
python数据类型 --> str
json.loads
strs = '{{1: 2, "name": "age", 'hehe': {"name": "chang"}}}'
dicts = json.loads(strs)
str --> python数据类型
json.dump()
dicts2 = {1: 2, "name": "age"}
f = open('1.txt', 'w')
json.dump(dicts2, f)
把dict写进file
json.load()
f = open('1.txt','r')
dicts = json.load(f)
把file中的读出来--》dict
网友评论