Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON array get length

Tags:

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

this is the source code

 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();     } 
like image 302
WARRW Avatar asked Feb 13 '12 21:02

WARRW


People also ask

How do I find the size of an array in JSON?

To obtain the size of a JSON-encoded array or object, use the json_size function, and specify the column containing the JSON string and the JSONPath expression to the array or object. To use the Amazon Web Services Documentation, Javascript must be enabled.

Does JSON have length?

The maximum length of a JSON type using a binary storage format is 16776192 bytes.


1 Answers

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.

like image 114
JMiao Avatar answered Oct 24 '22 04:10

JMiao