79605589

Date: 2025-05-04 12:00:47
Score: 1
Natty:
Report link

You can do it without gson, solely with json in a simple way, like this:

JSONArray jsonArray = new JSONArray(Files.readString(Paths.get("path/to/your/file.json"))); // This way it always works with the newest data in that file

for (Object element : jsonArray) {
    JSONObject jsonObject = (JSONObject) element;
    // You can now work with jsonObject, in your example, the cars
}
Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Aravind Hakka