Accessing members of items in a JSONArray with Java

后端 未结 6 1588
小蘑菇
小蘑菇 2020-11-22 16:23

I\'m just getting started with using json with java. I\'m not sure how to access string values within a JSONArray. For instance, my json looks like this:

{
         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 17:01

    In case it helps someone else, I was able to convert to an array by doing something like this,

    JSONObject jsonObject = (JSONObject)new JSONParser().parse(jsonString);
    ((JSONArray) jsonObject).toArray()
    

    ...or you should be able to get the length

    ((JSONArray) myJsonArray).toArray().length
    

提交回复
热议问题