[英]rest assured check the name is exist in the json response
我是放心的新人。使用放心的我試圖驗證是否找到了數據詳細信息。這里有兩個數據詳細信息。有時是2或3或5 am會得到如下響應並使用java
{
"queryPath": "/api/",
"nId": "f084f5ad24fcfaa9e9faea0",
"statusCode": 707
"statusMessage": "Success",
"results": {
"data": [
{
"id": "10248522500798",
"capabilities": [
"record",
"HDt"
],
"name": "errt2"
},
{
"id": "418143778",
"capabilities": [
"1record",
"HDy"
],
"name": "Livin"
}
]
}
}
使用代碼
JsonPath jsonResponse = new JsonPath(response.asString());
ArrayList<String> list = new ArrayList<String>();
list = jsonResponse.get("results.data"); //
if (list.size() < 1 ) {
SpiceCheck.fail("data not found! " + list.size());
}
而不是我想檢查數據名稱是否為null。我該如何保證。
如此一來,您就知道707之后缺少逗號。
為了驗證所有名稱都不為空,我將名稱解析為列表,然后逐個迭代名稱,並檢查它們是否不為空。
List<String> names = from(response.asString()).getList("results.data.name");
for(String name : names){
if(name == null){
// error handling code here
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.