java - API 响应数据数组计数小于 Rest Assured Java 中的实际计数
问题描述
我需要计算 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 数组的数量。目前计数错误。
解决方案
试试下面而不是 map ArrayList jsonList = response.jsonPath().get("data");
推荐阅读
- sql - 如何在 SQL 中将不同的列条目设置为列
- python - Matplotlib 从日期时间而不是时间绘制日期
- ios - 如何以编程方式快速将子视图添加到自定义视图
- c# - 在实体的 IQueryable 中使用相关实体的 IQueryable
- html - Angular生成刷新按钮单击
- python - 如果列是日期,熊猫,则按列名对数据框进行排序?
- html - 在 HTML 中生成的客户端中的 Swagger-Editor 空响应
- angular - 对 NGXS 表单 UpdateFormValue 执行副作用
- python-3.x - 需要建议阅读特定框架
- javascript - 重新映射 json 对象并将它们推送到一个数组中