json文件
"name": "Tom","age": 18,"score": {"math": ["192.168.0.1","192.168.0.2","192.168.0.3"],"chinese": 100
Python/ target=_blank class=infotextkey>Python读写代码:
import jsondef read_json(json_path):with open(json_path, 'r', encoding='utf-8') as f:data = json.load(f)print (data)print (type(data))print (data['name'])def write_json(json_path):test = {"name": "Tom","age": 18,"score":"math": ["192.168.0.1","192.168.0.2","192.168.0.3"],"chinese": 100with open("config.json", 'w', encoding='utf-8') as f:json.dump(test, f, indent=4, ensure_ascii=False)if __name__ == "__mAIn__":json_path = "config.json"read_json(json_path)write_json(json_path)
测试结果(目前项目上都是linux系统,使用读写json文件代替读写ini配置文件):