Hello. JSON string fragment.

{"creators":[ [ { "id":"30322", "professionKey":"director" } ], [ { "id":"1682023", "professionKey":"actor" }, { "id":"1876", "professionKey":"actor" } ], [ { "id":"31095", "professionKey":"producer" }, { "id":"1093329", "professionKey":"producer" } ]] } 

Or briefly {"creators":[ [ { "id":"30322", "professionKey":"director"} ],[....] ] } The difficulty lies in the following brackets. I believe that this is a two-dimensional array. Tried different options, c JSONArray, JSONObject. In the code below, put in getJSONArray (null) "". Please help.

 JSONArray creatorsContent = parentObject.getJSONArray("creators"); JSONArray finalArray = creatorsContent.getJSONObject(0).getJSONArray(null); professionKEy=creatorsContent.getString("professionKey"); 
  • Yes, this is exactly a two-dimensional array. - Nick Volynkin
  • Thanks, found the information. stackoverflow.com/questions/24179163/… In my case, JSONArray creatorsContent = parentObject.getJSONArray ("creators"); JSONArray creatorsContentFirst = creatorsContent.getJSONArray (0); professionKEy = creatorsContentFirst.getJSONObject (0) .getString ("professionKey"); - K. Chervyakovsky 5:02 pm

1 answer 1

I don't know which library you use, but in org.json it is done like this:

 JSONArray jsonArray = new JSONObject(jsonStr).getJSONArray("creators").getJSONArray(0); System.out.println(jsonArray.get(0).toString());