在Rest Assured Java中,API响应数据数组计数小于实际计数
我需要计算API响应数据数组。下面是数组计数的代码在Rest Assured Java中,API响应数据数组计数小于实际计数,java,rest-assured,Java,Rest Assured,我需要计算API响应数据数组。下面是数组计数的代码 ArrayList<Map<String,Object>> jsonList = response.jsonPath().get("data"); int i = jsonList.get(0).size(); System.out.println("Data Count in response : " +i); 我们必须计算响应数据数组的数量。当前计数错误。请尝试下面的内容,而
ArrayList<Map<String,Object>> jsonList = response.jsonPath().get("data");
int i = jsonList.get(0).size();
System.out.println("Data Count in response : " +i);
我们必须计算响应数据数组的数量。当前计数错误。请尝试下面的内容,而不是地图
ArrayList jsonList=response.jsonPath().get(“数据”) List jsonList=js1.getList(“数据”);
System.out.println(“响应中的数据计数:+jsonList.size());
下面的代码对我有用
ArrayList>jsonList=response.jsonPath().get(“数据”)
你得到JSON列表了吗?因为我看到的是数据是一个对象数组,ArrayList jsonList=response.jsonPath().get(“数据”);你要把它存储在地图上吗?尝试仅对象数组,我得到的arraylist非常完美,Postman和Json arraylist的值都相同,但只有count值较小。在Postman和Response中,arraylist计数为10,但int i=jsonList.get(0.size();只给出8。{country=ukin,airport\u name=London Luton airport}是json列表,总共显示10个值。请查看我需要知道您是否正在尝试计数键?get(0)->根据您在注释中附加的响应给出第一个键对象。还有,这是一张地图,你想数数什么。请附上调试时获得的JSON列表的快照。只需检查我是否已更新响应,现在我们需要计算响应数据中显示了多少组数组记录,就像数据现在包含两组记录一样,因此…显示相同的计数您可以共享完整的JSON只需检查“我已使用更多数据集更新了响应”。仅代码的答案被认为是低质量的:确保提供代码的功能以及如何解决问题的解释。如果你能在你的文章中添加更多的信息,这将有助于询问者和未来的读者。另请参见解释完全基于代码的答案:
{
"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",
},
]
}
List<Object> jsonList = js1.getList("data");
System.out.println("Data Count in response : " + jsonList.size());
int i = jsonList.size();