要编辑 JSON 文本,可以使用不同的编程语言和库来实现。下面是使用 Python 的示例代码:
import json
# 读取 JSON 文本文件
with open('example.json', 'r') as file:
data = json.load(file)
# 修改 JSON 数据
data['http_version'] = 'HTTP/3'
# 写入 JSON 文本文件
with open('example.json', 'w') as file:
json.dump(data, file, indent=4)
这个示例假设 JSON 文本文件名为 example.json
,它的内容类似于:
{
"http_version": "HTTP/1.1",
"request_type": "GET",
"url": "http://example.com"
}
上述代码会将 http_version
的值从 HTTP/1.1
修改为 HTTP/3
,然后将修改后的 JSON 数据写入到原来的文件中。