python接口自动化测试十二:对返回的json的简单操作
python接口自动化测试十二:对返回的json的简单操作
# 1、requests里面自带解析器转字典
print(r.json())
print(type(r.json()))
# 取出json中的'result_sk_temp'字段
# {"resultcode":"200","reason":"查询成功","result":{"sk":{"temp":"28","wind_direction":"东南风","wind_strength":"2级"
result = r.json()["result"]['sk']['temp']
print(result)
# 2、json模块转字典
import json
print(json.loads(r.text)) # json格式的str转dict
print(type(json.loads(r.text)))
# 查看返回内容,是字典格式才能转json
# html不能转成json
print(r.json()['reason'])
print(r.json()['result']['today']['weather'])
创作不易,转摘请标明出处。如果有意一起探讨测试相关技能可加博主QQ 771268289 博主微信:ding17121598
本文来自博客园,作者:怪圣卡杰,转载请注明原文链接:https://www.cnblogs.com/dwdw/p/9553150.html