【问题标题】:How can I extract response from json array in Karate如何从空手道中的 json 数组中提取响应
【发布时间】:2019-05-10 11:58:59
【问题描述】:

我正在尝试提取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

【问题讨论】:

    标签: json response karate jsonpath


    【解决方案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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多