Python读写json文件--json

import json


# 将数据写入json文件
def json_write_file():
    data={'name':'张三','age':12}
    with open('json.json','w') as f:
        f.write(json.dumps(data,indent=2, ensure_ascii=False))


# 从json文件中读数据
def json_read_file():
    with open('json.json','r')as f:
        data=json.load(f)
        print(data)

json_write_file()
json_read_file()

 

posted @ 2020-05-26 13:57  十一的杂文录  阅读(248)  评论(0编辑  收藏  举报