python接口自动化测试十二:对返回的json的简单操作,pythonjson,# 1、reques


# 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‘])
技术分享图片

python接口自动化测试十二:对返回的json的简单操作

评论关闭