求助:接口测试中,如何校验返回的json串值非空

返回结果的json串如下:如何校验"status"中 “recovered”: 非空
“”“
返回结果的json字符串:
{
“status”: {
“recovered”: 30,
“dealing”: 20,
“toDeal”: 10,
“closed”: 40
},
“level”: {
“1”: 10,
“2”: 10,
“3”: 10,
“4”: 10
}
}
”“”

使用jsonpath语法,试试

jsonpath(f"$.status.recovered[*]", res)

可以用len判断一下

我可能理解偏了 我以为是如何拿“recovered”了

数据为json_data,获取recovered的值,如下:
value = json_data[‘status’][‘recovered’]
判断是否为空,(这里要看你空数据返回情况)
if value == None:
print(“recovered is none”)
else:
print(“recovered is not none”)

aasert json_data[‘status’][‘recovered’] is not None 就可以了吧

1 个赞

感谢,就是用这种方式判断的

谢谢思寒老师,已解决