如何提取没有 "name" 的休息响应
How to extract a rest response that don't have a "name"
如何提取响应正文中没有名称的对象?
有效负载示例:
[
"0UOIP8AB45B138752172",
"16GW0K3I6SX162376934",
"16JMPMJWB1P111816144",
"1ATU22DNPF2115778748",
"1MD7WEAY3VX166052653",
"2G8ITN9TM04162374892",
"2GJR1LBMCZJ187945453",
"2RK7A3YGTAA105827565",
"2SZ04KI5NYO185742410",
"2ZPHJYIDHOL193996774"
]
RestAssured 片段。
RequestSpecification requestSpecification = new RequestSpecBuilder()
.setBaseUri(domain).build();
return given()
.spec(requestSpecification).log().all()
.contentType(APPLICATION_JSON)
.header(X_AUTH_TOKEN, token)
.get(path).then()
.assertThat().statusCode(201).log().ifError()
.extract().path(); // what do I write here?
您发布的负载不正确json。但是,假设这是你 JSON
[ "0UOIP8AB45B138752172",
"16GW0K3I6SX162376934",
"16JMPMJWB1P111816144",
"1ATU22DNPF2115778748",
"1MD7WEAY3VX166052653",
"2G8ITN9TM04162374892",
"2GJR1LBMCZJ187945453",
"2RK7A3YGTAA105827565",
"2SZ04KI5NYO185742410",
"2ZPHJYIDHOL193996774"
]
你不能使用 path
方法,因为你在这里没有路径。但是,您可以将此 JSON 数据提取为字符串数组数据。
String[] jsonData = given()
.spec(requestSpecification).log().all()
.contentType(APPLICATION_JSON)
.header(X_AUTH_TOKEN, token)
.post(path).then()
.assertThat().statusCode(201).log().ifError()
.extract().as(String[].class);
//Add any assertions on the length of the array.
return jsonData[position]; // Assuming position is the index of the String value to be retrieved.
在这里,您必须确实知道要从 JSON 数组数据中提取的值的位置。
如何提取响应正文中没有名称的对象?
有效负载示例:
[
"0UOIP8AB45B138752172",
"16GW0K3I6SX162376934",
"16JMPMJWB1P111816144",
"1ATU22DNPF2115778748",
"1MD7WEAY3VX166052653",
"2G8ITN9TM04162374892",
"2GJR1LBMCZJ187945453",
"2RK7A3YGTAA105827565",
"2SZ04KI5NYO185742410",
"2ZPHJYIDHOL193996774"
]
RestAssured 片段。
RequestSpecification requestSpecification = new RequestSpecBuilder()
.setBaseUri(domain).build();
return given()
.spec(requestSpecification).log().all()
.contentType(APPLICATION_JSON)
.header(X_AUTH_TOKEN, token)
.get(path).then()
.assertThat().statusCode(201).log().ifError()
.extract().path(); // what do I write here?
您发布的负载不正确json。但是,假设这是你 JSON
[ "0UOIP8AB45B138752172",
"16GW0K3I6SX162376934",
"16JMPMJWB1P111816144",
"1ATU22DNPF2115778748",
"1MD7WEAY3VX166052653",
"2G8ITN9TM04162374892",
"2GJR1LBMCZJ187945453",
"2RK7A3YGTAA105827565",
"2SZ04KI5NYO185742410",
"2ZPHJYIDHOL193996774"
]
你不能使用 path
方法,因为你在这里没有路径。但是,您可以将此 JSON 数据提取为字符串数组数据。
String[] jsonData = given()
.spec(requestSpecification).log().all()
.contentType(APPLICATION_JSON)
.header(X_AUTH_TOKEN, token)
.post(path).then()
.assertThat().statusCode(201).log().ifError()
.extract().as(String[].class);
//Add any assertions on the length of the array.
return jsonData[position]; // Assuming position is the index of the String value to be retrieved.
在这里,您必须确实知道要从 JSON 数组数据中提取的值的位置。