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

原文地址: https://www.cveoy.top/t/topic/iMSi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录