So, I am using json-simple library in my project, and this is what I have right now: (I just want to print out each of the objects from the JSON file)
import java.io.*; import java.util.*; import org.json.simple.*; import org.json.simple.parser.*; public class App { public static void main(String[] args) { JSONParser parser = new JSONParser(); try { Object obj = parser.parse(new FileReader("src/movies.json")); JSONObject jsonObject = (JSONObject) obj; JSONArray upcoming = (JSONArray) jsonObject.get("Upcoming"); JSONArray current = (JSONArray) jsonObject.get("Current"); System.out.println("Upcoming Movies:"); Iterator upcomingIterator = upcoming.iterator(); while (upcomingIterator.hasNext()) { String title = (String) ((HashMap) upcomingIterator.next()).get("title"); System.out.println("title: " + title); String numberOfSeats = (String) ((HashMap) upcomingIterator.next()).get("numberOfSeats"); System.out.println("numberOfSeats: " + numberOfSeats); String synopsis = (String) ((HashMap) upcomingIterator.next()).get("synopsis"); System.out.println("synopsis: " + synopsis); } } catch (Exception e) { e.printStackTrace(); } } } and this is what the JSON file looks like:
{ "Upcoming": [ { "title": "Black Panther: Wakanda Forever", "status": "Current", "showtimes": [ "11:00", "12:00", "13:00" ], "theater": [ "Lubbock", "Amarillo", "Plainview", "Snyder" ], "numberOfSeats": "55", "synopsis": "The people of Wakanda fight to protect their home from intervening world powers as they mourn the death of King T'Challa.", "runtime": "161 min", "prices": [ "$5", "$6", "$10" ], "reviews": [ "Great Movie", "Best Movie", "The greatest movie ever", "I like the lead in this movie" ], "castInfo": [ "Letitia Wright", "Lupita Nyong'o", "Danai Gurira", "Winston Duke" ] }, { "title": "Thor: Love and Thunder", "status": "Upcoming", "showtimes": [ "14:30", "19:15", "19:45" ], "theater": [ "Lubbock", "Plainview", "Abilene" ], "numberOfSeats": "64", "synopsis": "Thor enlists the help of Valkyrie, Korg and ex-girlfriend Jane Foster to fight Gorr the God Butcher, who intends to make the gods extinct.", "runtime": "118 min", "prices": [ "$6", "$7", "$10" ], "reviews": [ "Great Movie", "Best Movie", "The greatest movie ever", "I like the lead in this movie" ], "castInfo": [ "Chris Hemsworth", "Natalie Portman", "Christian Bale", "Tessa Thompson" ] } ] } After running the code above, I am getting the following output which is not really consistent with the JSON data. Can someone please explain how can I solve this?

upcomingIterator.next()three times in the loop, whileUpcomingonly contains 2 elements. You should callnext()only once per loop iteration, assign it to a local variable, and then use it for the remainder of the loop. In case you hadn't noticed it, you printed the title of the first array element ofUpcoming, and the number of seats of the second array element. If you had had three elements in the array, you would have printed the synopsis of the third.