标签:转换 int json对象 jsonp size tags python name load
#在python中字典就是json对象
import json
str_dict={"name":"xiaoming","age":"18"} #json.dumps :把字典转换成字符串
str1=json.dumps(str_dict)
print(type(str1))
str2=‘{"name":"xiaoming","age":"18"}‘ #json.loads :把字符串转换成字典
str_json=json.loads(str2)
print(type(str_json))
print(str_json[‘age‘])
# jsonpath对json数据解析
import jsonpath
jsondata={"tags":[{"id":2,"name":"星标组","count":0},{"id":100,"name":"冰淇淋","count":0},{"id":101,"name":"百事可乐","count":0},{"id":102,"name":"衡阳","count":1},{"id":103,"name":"上海777","count":0}]}
value=jsonpath.jsonpath(jsondata,‘$.tags[2].name‘)
print(value[0])
json.dumps、json.loads以及jsonpath解释举例
标签:转换 int json对象 jsonp size tags python name load
原文地址:https://www.cnblogs.com/lvhuayan/p/14901393.html