我需要计算 API 响应数据数组。下面是数组计数的代码。
ArrayList<Map<String,Object>> jsonList = response.jsonPath().get("data");
int i = jsonList.get(0).size();
System.out.println("Data Count in response : " +i);
API 的响应如下
{
"response": {
"code": 200,
"status": "success",
"alert": [
{
"message": "Success",
"type": "success",
"skippable": 1
}
],
"from_cache": 0,
"is_data": 1
},
"data": [
{
"airport_name": "London Luton Airport",
"city": "London",
"country": "United Kingdom",
},
{
"airport_name": "London Biggin Hill Airport",
"city": "Biggin Hill",
"country": "United Kingdom",
},
]
}
我们必须计算响应中 Data 数组的数量。当前计数错误。
试试下面而不是地图 ArrayList jsonList = response.jsonPath((.get("data"(;
List<Object> jsonList = js1.getList("data");
System.out.println("Data Count in response : " + jsonList.size());
下面的代码对我有用 ArrayList> jsonList = response.jsonPath((.get("data"(;
int i = jsonList.size();