import json # 假设您有一个名为"data.json"的JSON文件 path="C:/Users/Administrator/Desktop/test/a.json" with open(path, "r") as f: data = json.load(f) add_dict={ "add":"add", "sub":"sub" } # print(data["test"]) i=0 while i<len(data["test"]): if data["test"][i]["a"]=="bbb": data["test"].insert(i,add_dict) i += 1 i+=1 # # # 打开JSON文件并写入修改后的数据 with open(path, "w") as f: json.dump(data, f) print(data) # print(type(data["test"]))
python新增插入list
最新推荐文章于 2024-10-04 00:46:18 发布