【Python】向json文件中追加新的对象
def get_json(path, write_path):
file = open(path, encoding='utf8', errors='ignore')
file_lines = file.read()
file.close()
file_json = json.loads(file_lines)
json_txt = []
for json_data in file_json:
if isinstance(json_data, dict):
print(json_data)
nums = random.randint(1, 100)
# 向json文件中写入新的键值对
json_data["number"] = str(nums)
json_txt.append(json_data)
return