python 中 json读写

import json

# 读取json文件
def read_json(file_name):
    json_file = open("%s" % file_name, "rb")
    get_json = json.load(json_file)
    json_file.close()
    return get_json

# 写入json文件
def write_json(file_name, json_context):
    json_file = open("%s" % file_name, "wb")
    to_json = json.dumps(json_context)
    json_file.write(to_json)
    json_file.close()

发表评论

电子邮件地址不会被公开。 必填项已用*标注