文件中有多条json,想用python语法给文件中每条json追加一些字段添加数据。如何做呢?
收起
先读再写,比如这样
import json new = {"new":"test"} with open("test.json") as f: a = json.load(f) a.update(new) with open("test.json", "w") as f: json.dump(a, f)
报告相同问题?