1

I am currently using the Json-simple jar file and need to convert my json object into json array, I read on many places to use:


JSONParser parse = new JSONParser();

JSONObject jobj = (JSONObject) parse.parse(jsonString);


JSONArray arr = jsonObject.getJSONArray("users");

However the getJSONArray() method isn't being recognized. It says cannot find symbol. I have imported all of the org.json package but not sure how this works.

My JSON is coming from a url and is:

{
  "warnings":[

   ],

  "users":[
      {
         "id":12345678,
         "username":"abc123",
         "firstname":"ABC",
         "lastname":"DEF",
         "fullname":"ABC",
         "email":"abc@gmail.com",
         "department":"Autoz",
         "idnumber":"1234",
         "firstaccess":2552,
         "lastaccess":4242,
         "auth":"ldap",
         "suspended":false,
         "confirmed":true,
         "lang":"en",
         "theme":"",
         "timezone":"99",
         "mailformat":1,
         "description":"Software Engineer",
         "descriptionformat":1,
         "city":"Lahore",
         "profileimageurlsmall":"srwegwegdrz",
         "profileimageurl":"rbdrrebhez"
      }
   ]

}




  • json-simple isn't suppored anymore, you should use Jackson or Gson, those are the most popular libraries for parsing JSON in the Java world. – Nyamiou The Galeanthrope May 05 '20 at 13:24
  • Hi I tried using gson to get the json object. ``` Gson gson = new Gson(); JsonElement jsonElement = new JsonParser().parse(jsonString); JsonObject jsonObject = jsonElement.getAsJsonObject(); ``` But not sure how to convert it later to array I tried but could't get to it –  May 05 '20 at 13:30

0 Answers0