本文共 493 字,大约阅读时间需要 1 分钟。
Dump
# -*-coding:utf-8 -*-__author__ = 'xiaojiaxin'__file_name__ = 'dump'import jsondict={"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 jsondict={"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