Python 如何将字典转换为 JSON 文件并保存
文章目录
Python 怎么将dict字典转换成json文件保存
1. json.dump()
- 公式:json.dump(person_dict, json_file, indent=4)
2. with open(“要打开的文件路径/保存的地址file_name”, “w”) as outfiles:
# 将dict这个字典转换为json格式,并保存在task1.json这个文件里。每组key:value前缩进4个空格
with open("task1.json", "w") as outfiles:
json.dump(dict, outfiles, indent = 4)
作者:skylar0