使用json读写文件中的数据

把json的数据写入到文件中

import json

with open('data.json','w+') as f:

    json.dump({"name":"张彪"},f)

把json的数据从文件中读取出来

import json

with open('data.json','r') as f:
 
    x=json.load(f)
    print(x,type(x))

猜你喜欢

转载自www.cnblogs.com/crazymagic/p/8903747.html