import json
dict = {'one':1,'two':0,'three':False,'four':None}
j = json.dumps(dict)
dict2 = json.loads(j)
print('================字典进,字典出================')
with open('fjson.json','w') as f:
json.dump(dict, f)
with open('fjson.json', 'r') as f:
jf = json.load(f)
print(type(jf))
print(jf)
print('================json进,json出================')
with open('fjson.json','w') as f:
json.dump(j, f)
with open('fjson.json', 'r') as f:
jj = json.load(f)
print(type(jj))
print(jj)
打印结果:
================字典进,字典出================
<class 'dict'>
{'one': 1, 'two': 0, 'three': False, 'four': None}
================json进,json出================
<class 'str'>
{"one": 1, "two": 0, "three": false, "four": null}