import json

读取 JSON 数据

with open('data.json', 'r') as file: data = json.load(file)

替换字符串

new_data = json.dumps(data).replace("old_string", "new_string")

输出替换后的 JSON 数据

print(new_data)

保存替换后的 JSON 数据到文件

with open('new_data.json', 'w') as file: file.write(new_data)

import json# 读取 JSON 数据with opendatajson r as file data = jsonloadfile# 替换字符串new_data = jsondumpsdatareplaceold_string new_string# 输出替换后的 JSON 数据printnew_data# 保存替换后的 JSON 数据到文件with opennew_datajso