首页 > 解决方案 > 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 数组的数量。目前计数错误。

标签: javarest-assured

解决方案


试试下面而不是 map ArrayList jsonList = response.jsonPath().get("data");


推荐阅读