Dump和load
Dump
# -*-coding:utf-8 -*-
__author__ = 'xiaojiaxin'
__file_name__ = 'dump'
import json
dict={"name":"jiaxin","sex":"female"}
f=open("dump_test","w")
json.dump(dict,f)
#等价于下面两句话
# data=json.dumps(dict)
# data=f.write(data)
f.close()
load
# -*-coding:utf-8 -*-
__author__ = 'xiaojiaxin'
__file_name__ = 'load'
import json
dict={"name":"jiaxin","sex":"female"}
f=open("dump_test","r")
print(json.load(f))
#等价于
# data=f.read()
# print(json.loads(data))
f.close()
转载于:https://blog.51cto.com/10777193/2093378