示例:import jsonconfig = {"host": "localhost", "port": 8080, "debug": True}with open("config.json", "w", encoding="utf-8") as f: json.dump(config, f, indent=2)with open("config.json", "r", encoding="utf-8") as f: loaded = json.load(f) print(loaded["host"])