返回顶部

使用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))

 

posted @ 2018-04-21 21:10  Crazymagic  阅读(1540)  评论(0编辑  收藏  举报