[英]Get data from outside the root level of response
我對REST還是很陌生,還無法弄清楚這一點。
我有這樣的回應:
{
"StatusCode": 200,
"Result": {
"CustomerStuff": {
"Name": "John",
"State": "Oregon",
"GetEmail": false
},
"eText": "Will only get paper mail. "
}
}
我通常將響應主體保存為字符串,然后使用JsonPath來獲取所需的內容。
String responseBody = given().body().when().etc...;
JsonPath jsonPath = new JsonPath(responseBody).setRoot("Result.CustomerStuff");
然后得到我需要的:
String name = jsonPath.get("name");
我不知道如何獲得“ eText”值。 它不在響應的同一段中。
有什么建議么?
你應該用
JsonPath jsonPath = new JsonPath(responseBody).setRoot("Result")
然后調用jsonPath.get("eText")
以獲得所需的值。 您仍然可以使用jsonPath.get("CustomerStuff")
訪問CustomerStuff
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.