上代码:
def write_json(filename, data_dict):
# 将字典数据写入到json文件中
with open(filename, 'w', encoding="utf8") as fp:
json.dump(data_dict, fp, ensure_ascii=False)
def read_json(filename):
# 读取json文件内容, 返回字典格式
with open(filename, 'r', encoding="utf8") as fp:
data_dict = json.load(fp)
return data_dict
参考资料:
python操作json文件