如何获取来自 json 数组的响应的大小

How to get size of a response coming from json array

我有一个 json 响应,我在其中存储了一些数据,现在我想获取 json 数组 [=12] 中存在的 json 对象的大小=]

[
    {
        "type": "Insurance Policies",
        "count": 2,
        "category_id": "1"
    },
    {
        "type": "Mediclaim Policies",
        "count": 1,
        "category_id": "2"
    },
    {
        "type": "Mutual Fund Policies",
        "count": 1,
        "category_id": "3"
    }
]

使用下面的代码获取 JSON 数组长度

String jsonStringContent = [
    {
        "type": "Insurance Policies",
        "count": 2,
        "category_id": "1"
    },
    {
        "type": "Mediclaim Policies",
        "count": 1,
        "category_id": "2"
    },
    {
        "type": "Mutual Fund Policies",
        "count": 1,
        "category_id": "3"
    }
];

JSONArray jsonArray = new JSONArray(jsonStringContent);

int size = jsonArray.length();

好的,我得到了答案我只需要创建 JSONArray 的对象并将响应存储在该对象中,只需要调用 object.length()