android - json 数组中元素的计数

标签 android json

这是我的 JSON 数组,

[{
    "textinput": [{
        "position": 0,
        "dependency": "no",
        "id": 0,
        "label": "single1",
        "Itype": "textinput"
    }, {
        "position": 1,
        "dependency": "no",
        "id": 1,
        "label": "single2",
        "Itype": "textinput"
    }, {
        "position": 2,
        "dependency": "no",
        "id": 2,
        "label": "single3",
        "Itype": "textinput"
    }, {
        "position": 3,
        "dependency": "no",
        "id": 3,
        "label": "single4",
        "Itype": "textinput"
    }, {
        "position": 4,
        "dependency": "no",
        "id": 4,
        "label": "single5",
        "Itype": "textinput"
    }, {
        "position": 5,
        "dependency": "no",
        "id": 5,
        "label": "single6",
        "Itype": "textinput"
    }]
}]

我想获得有关计算上述数组中 position 数量的帮助。

最佳答案

你错过了 j :P

try {
     JSONArray jsonArray = new JSONArray("Your response");    
     int count = jsonArray.getJSONObject(0).getJSONArray("textinput").length();
 } catch (JSONException e) {
     e.printStackTrace();
 }

关于android - json 数组中元素的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38628193/

相关文章:

android - 如何在Andengine中显示alertDialog?

android - 为监听器创建单独的类

java - 如何让我的应用程序在 Android 中等待?

android - MediaRouter 的 Chromecast Nullpointer 异常

javascript - 调用网络服务 AngularJS

java - 我有一个关于显示器问题的非常菜鸟的询问

json - Logback 附加程序将消息作为 HTTP 消息发布

php - 从 MySQL 的两个表中转储 json 格式的数据

javascript - 如何使用 javascript 或 jquery 将键和值添加到 json

javascript - 解析 Highcharts 的 JSON 数据