[Tips] python json解析

mac2022-06-30  34

将字符串内容解析为python对象,和将python对象转换为字符串内容,使用:

json.loads(text字符串) json.dumps(python对象)# python3import jsondata={}json_str = json.dumps(data)print ("Python 原始数据:", repr(data1))print ("JSON 对象:", json_str)data1 = json.loads(json_str)

  

如果是处理文件,使用:

json.load(文件句柄) json.dump(python对象,文件句柄)with open('data.json', 'w') as f: json.dump(data, f)with open('data.json', 'r') as f: data = json.load(f)

  

转载于:https://www.cnblogs.com/immortalBlog/p/11510788.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)