我试图只改变一个键的值,但结果是我的整个json数据被附加到了旧的数据。
Here is the script
import json
with open('test.json', "r+") as json_file:
wifi = json.load(json_file)
status = wifi["wifi_status"]
wifi["wifi_status"] = "off"
json.dump(wifi, json_file)
这是json文件
{"wifi_status":"on","ssid":"my_router","pw":"my_password"}
{"wifi_status":"on","ssid":"my_router","pw":"my_password"}{"wifi_status": "off", "ssid": "my_router", "pw": "my_password"}
有没有一种方法可以在不倾倒所有信息的情况下修改一个值?