Discuss / Python / 把JSON写入一个文件

把JSON写入一个文件

Topic source

雨鸢梦

#1 Created at ... [Delete] [Delete and Lock User]
import json
d = dict(name='Bob', age=20, score=88)
f=open('E:\lianxi\python\json.txt','w')  #需要注意的是这里需要使用w而不是wb
print(json.dump(d,f))
f.close()

f=open('E:\lianxi\python\json.txt','r')
d=json.load(f)
f.close()
print(d)


  • 1

Reply