gpt4 book ai didi

android - json 数组中元素的计数

转载 作者:行者123 更新时间:2023-11-30 01:08:47 25 4
gpt4 key购买 nike

这是我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com