如何使用 java 从 RestAssured 中的 API 响应中获取键值

问题描述 投票:0回答:1

我在下面有一个 API 响应。我想从 JSON 数组内的响应中获取一个值。

{
  "Code": [
    {
      "id": "string1",
      "istrue": false,
      Text": "hdjdjkdk123"
    }
  ]
}

我正在使用 JsonPath 类来获取

String resp = response.asString();
JsonPath js = new JsonPath(resp);
js.get("ciext").toString();

任何人请帮助我如何获取“id”或“ciText”的值???

rest rest-assured web-api-testing rest-assured-jsonpath automation-testing
1个回答
0
投票

正确的路径是:

js.get("cipherTexts[0].id")
//or
js.get("cipherTexts[0].cipherText")
© www.soinside.com 2019 - 2024. All rights reserved.