【发布时间】:2020-10-28 15:44:14
【问题描述】:
我需要从 Rest Assured 建模请求返回的 JSON 响应数据中获取两个值:
public void getCustomerStatuses() {
Response response =
given().header("X-AC-User-ID","test-user").
spec(customerApiSpec).
when().
get("/api/v6/status/" + ref + "/").
then().
assertThat().statusCode(200).extract().response();
custStatusId = response.path("$.cust[?(@.name=='STATUS_ID')].id");
custRenewalId = response.path("$.cust[?(@.name=='RENEWAL_ID')].id");
System.out.println(custStatusId);
System.out.println(custRenewalId);
}
这会抛出和java.lang.IllegalArgumentException: Invalid JSON expression:Script1.groovy: 1: Unexpected input: '$.cust[?' @ line 1, column 36. $.cust[?(@.name=='STATUS_ID')].id
获得这些的正确、最佳方式是什么?我知道我可以将 extract().response().jsonPath(); 链接到请求中,但不确定如何获得 >1 值
【问题讨论】:
标签: json rest-assured jsonpath