String jsonString = "[\"apple\", \"banana\", \"orange\"]"; JSONArray jsonArray = new JSONArray(jsonString); String fruit = jsonArray.getString(1); System.out.println(fruit); // Output: banana
String jsonString = "[{\"name\":\"John\", \"age\":30}, {\"name\":\"Mary\", \"age\":25}]"; JSONArray jsonArray = new JSONArray(jsonString); JSONObject person = jsonArray.getJSONObject(0); String name = person.getString("name"); int age = person.getInt("age"); System.out.println(name + " is " + age + " years old."); // Output: John is 30 years old.In this example, we create a JSONArray object from a JSON string that contains an array of person objects. Then, we use the getString method to get the name of the first person in the array, and the getInt method to get their age. Finally, we print out a message with their name and age. Overall, the org.json package library in Java provides a useful set of classes for working with JSON data, and the JSONArray getString method allows us to easily extract string values from a JSON array.