JSON数组获取长度 [英] JSON array get length
本文介绍了JSON数组获取长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法获取JSON数组的数组长度.当我使用length();方法不起作用,在Netbeans中显示为红色下划线
I can't get the array length of the JSON array. when I using length(); method it is not working, it show as red underline in Netbeans
这是源代码
try {
JSONObject myjson = JSONObject.fromObject(practiceInfoByUsername);
//JSONArray nameArray = myjson.names();
final JSONArray jar = myjson.getJSONArray("_types");
for(int i=0; i<jar.length(); i++)
{
String p = jar.getString(i);
Log.i("p",p);
}
} catch (JSONException e) {
e.printStackTrace();
}
推荐答案
注意:如果您正在使用(导入)org.json.simple.JSONArray
,则必须使用JSONArray.size()
来获取所需的数据.但是,如果您使用的是org.json.JSONArray
,请使用JSONArray.length()
.
Note: if you're using(importing) org.json.simple.JSONArray
, you have to use JSONArray.size()
to get the data you want. But use JSONArray.length()
if you're using org.json.JSONArray
.
这篇关于JSON数组获取长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文