简体   繁体   中英

How to get size of a response coming from json array

I've a json response in which I've stored some data and now I want to get the size of the json objects present in json array

[
    {
        "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"
    }
]

Use below code for getting JSON Array Length

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM