持续更新中
感受python的强大之case列举:
import json map={"name": "张三", "age": 18, "address": "北京"} list=[] for i in range(3): list.append(map) with open('output.json','w', encoding='utf-8') as fp: json.dump(list, fp, ensure_ascii=False, indent=4)
'运行
生成文件如下
[ { "name": "张三", "age": 18, "address": "北京" }, { "name": "张三", "age": 18, "address": "北京" }, { "name": "张三", "age": 18, "address": "北京" } ]
'运行
json.dump不带indent=4 则生成一行内容:
[{"name": "张三", "age": 18, "address": "北京"}, {"name": "张三", "age": 18, "address": "北京"}, {"name": "张三", "age": 18, "address": "北京"}]
'运行