I came here and looking how to get the number of elements inside a JSONArray
. From your question i used length()
like that:
JSONArray jar = myjson.getJSONArray("_types");
System.out.println(jar.length());
and it worked as expected. On the other hand jar.size();
(as proposed in the other answer) is not working for me.
So for future users searching (like me) how to get the size of a JSONArray
, length()
works just fine.