我如何从空手道中的json数组中提取响应

时间:2019-05-10 11:59:00

标签: json response karate jsonpath

我正在尝试提取response[0].otpValue,但是它不起作用

我试图:

get[0] response.id
response[0].otpValue
{
    "errorCode": null,
    "response": [
        {
            "createdTimestamp": 1557314537720,
            "lastUpdatedTimestamp": 1557314537720,
            "createdBy": null,
            "lastUpdatedBy": null,         
            "otpValue": "5346",
            "expiryTimestamp": 1556807308797,
            "validNow": false,
            "sessionUserId": null
        }
    ],
    "status": "SUCCESS",
    "errorMessage": null
}

我希望从json响应中获取otpValue

* def firstOtp = response[0].id

1 个答案:

答案 0 :(得分:1)

* def answer = { "errorCode": null, "response": [ { "createdTimestamp": 1557314537720, "lastUpdatedTimestamp": 1557314537720, "createdBy": null, "lastUpdatedBy": null, "otpValue": "5346", "expiryTimestamp": 1556807308797, "validNow": false, "sessionUserId": null } ], "status": "SUCCESS", "errorMessage": null }
* def firstOtp = answer.response[0].otpValue
* match firstOtp == "5346"