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 = https://www.isolves.com/it/cxkf/yy/Python/2022-11-21/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配置文件):
文章插图
【python读写json文件】
推荐阅读
- 使用python selenium模拟登陆163并发送邮件
- MySql中json类型数据的查询以及在MyBatis-Plus中的使用
- python 组的创建和删除
- 编程语言迎来“取代潮”,Python、Java、C/C+谁最危险?
- python爬虫之Scrapy框架,基本介绍使用以及用框架下载图片案例
- python + selenium实现gitlab全文搜索
- import python意思 python import是什么
- Python __init__ python中的init怎么理解
- python里面input什么意思 pythoninput是什么意思
- nums在python中是什么意思 pop在python中是什么意思