-1

how can i read the json file i have and then save it in a JSONArray?

And by JSONArray I mean org.json.JSONArray, not the simple.JSONArray!

JSONParser parser = new JSONParser();
JSONArray obj = (JSONArray) parser.parse(new FileReader(pathJson));

I've tried this but i get an error when I try to use obj.get() or obj.opt() method which says im not allowed to cast simpleJSONArray to JSONArray

What should I do?

Liuk
  • 351
  • 1
  • 13
  • 2
    Does this answer your question? [Gson and deserializing an array of objects with arrays in it](https://stackoverflow.com/questions/3763937/gson-and-deserializing-an-array-of-objects-with-arrays-in-it) – Daniel Brose Jan 08 '20 at 23:47

1 Answers1

0

Use the Gson library. In particular you would use the method fromJson.

It returns an array of your object. So, you need to create a Java class that represents your object in json file.

Liuk
  • 351
  • 1
  • 13