python提取json中key的value值
作者:互联网
比如下面的案例是,取店铺名称
接口返回数据如下:{"Code":0,"Msg":"ok","Data":{"StoreName":"小贝书屋",
"StoreLogo":"xkdnewyun/systemfile/images/100e478a75754c6f9237cd25e5874ca1.jpg","Contacts":"小贝书屋",
"TelPhone":"18674731640","Introduction":"","IndustryFirstId":"21","IndustryFirst":"亲子",
"IndustrySecondId":"2112","IndustrySecond":"亲子购物","AllProductNum":2,"LatestNum":1},"TraceFlag":null}
取其中“StoreName”值“小贝书屋”的方法和步骤如下
1、首先插入 ipmort json
2、接口返回的数据r = requests.get(url,data=data,headers= header) #请求url,获得返回的数据信息
text = r.text
print(text) #获得的返回数据使用text方法进行获取
3、将响应内容转换为json对象jsonobj = json.loads(text)#将响应内容转换为Json对象
4、从json对象内取出需要的内容toCntPercent = jsonobj['Data']['StoreName'] # 从Json对象获取想要的内容
转自https://blog.csdn.net/weixin_39732825/article/details/110040445?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ETopBlog-1.topblog&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ETopBlog-1.topblog&utm_relevant_index=1
标签:relevant,StoreName,python,text,小贝,value,blog,json 来源: https://www.cnblogs.com/huaixiaohai/p/16199644.html