- 将信息写入json,并且需要正确显示中文
with open(json_fullname, 'w') as f:
json.dump(words, f, ensure_ascii=False)
- 将信息写入json,正确显示中文,对不同层级进行缩进 方便查看
with open(json_save_fullpath, 'w+') as f:
json.dump(info, f, indent=4, ensure_ascii=False, separators=(',', ':'))
- 读取json文件,得到dict
with open(json_src_fullpath) as f:
info = json.load(f)