当前位置 : 主页 > 网络安全 > 测试自动化 >

接口自动化

来源:互联网 收集:自由互联 发布时间:2021-06-19
import jsonpathdic = { " error_code " : 0, " stu_info " : [ { " id " : 2057 , " name " : " xiaohei " , " sex " : " nan " , " age " : 29 , " addr " : " beijing " , " grade " : " tianxie " , " phone " : " 18712321234 " , " gold " : 100 } ]}s
import jsonpath
dic={
        "error_code": 0,
        "stu_info": [
                {
                        "id": 2057,
                        "name": "xiaohei",
                        "sex": "nan",
                        "age": 29,
                        "addr": "beijing",
                        "grade": "tianxie",
                        "phone": "18712321234",
                        "gold": 100
                }
        ]
}


s=jsonpath.jsonpath(dic,$..age)
s2=jsonpath.jsonpath(dic,$..error_code)
s3=jsonpath.jsonpath(dic,$..abc)
print(s)
print(s2)
print(s3)
#如果取到的值不存在就返回False
网友评论