M. Kaan M. Kaan - 1 month ago 22
Java Question

How to create JSON object without using String?

I want to create an android application that uses an API to show some information on a listview. The problem I am facing is that the json file that I want to download is too big for String the object. My instructor told me that Android Studio somehow limited the size of the String. I get the error "constant string too long".
Is it possible for me to download that information as a json file (it is .geojson actually) and store it somewhere in the disk (actually I can download the file), and then parse it without using any String object by reading it from the file itself. OR Can you suggest another way of doing it since I am new in programming?


The solution I found is that using simple JSON simple library in my project. You can get it from here. After I downloaded the JSON file to the storage, I parsed it by using the code below:

    JSONParser parser = new JSONParser();
    Object obj = null;

    try {
        obj = parser.parse(new FileReader(directory of the folder + "/fileName.extension"));
    } catch (IOException e) {
    } catch (org.json.simple.parser.ParseException e) {

    JSONObject jsonObject = (JSONObject) obj;

Now you can use jsonObject as how you want.