![](/img/trans.png)
[英]How to get JSON ARRAY and JSON object response from retrofit response?
[英]How to get size of a response coming from json array
我有一个 json 响应,其中存储了一些数据,现在我想获取 json 数组中存在的 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.