-1

I am working with android .I want to parse a nested json array without name.How can I parse these array and store these into a list and the i need to make list of these list.How can I parse these arrays.Thanks in advance.

[
    [
        [
            72.837,
            18.956,
            0
        ],
        [
            72.817,
            18.956,
            0
        ],
        [
            72.8095,
            18.956,
            0
        ],
        [
            72.8082,
            18.956,
            0
        ],
        [
            72.808,
            18.956,
            0
        ],
        [
            72.8076,
            18.9562,
            0
        ],
        [
            72.8072,
            18.9564,
            0
        ],
        [
            72.8071,
            18.9578,
            0
        ],
        [
            72.807,
            18.9617,
            0
        ],
        [
            72.807,
            18.9757,
            0
        ],
        [
            72.8072,
            18.9767,
            0
        ],
        [
            72.8072,
            18.9768,
            0
        ],
        [
            72.8074,
            18.9774,
            0
        ],
        [
            72.8088,
            18.9777,
            0
        ],
        [
            72.8112,
            18.978,
            0
        ],
        [
            72.8414,
            18.9779,
            0
        ],
        [
            72.8438,
            18.9778,
            0
        ],
        [
            72.8439,
            18.9773,
            0
        ],
        [
            72.8439,
            18.9606,
            0
        ],
        [
            72.8439,
            18.9583,
            0
        ],
        [
            72.8428,
            18.9566,
            0
        ],
        [
            72.8423,
            18.9562,
            0
        ],
        [
            72.8403,
            18.9561,
            0
        ],
        [
            72.8376,
            18.956,
            0
        ],
        [
            72.837,
            18.956,
            0
        ]
    ]
]
1
  • Did you already load that in a JSONArray in your code? Or do you need that part as well? Commented Oct 21, 2015 at 7:49

2 Answers 2

1

You can do

JSONArray array = new JSONArray(response); //Where response is your json string

Then you can iterate throws this arrays using a for loop

for(int i=0; i<array.length(); i++) {
    //Do something using :
    //array.get(i) or
    //array.getJsonArray(i) or
    //array.getDouble(i) or
    //...
}

Here is the doc for JsonArray

EDIT If you want to convert your nested jsonArray into nested java list you can do (not tested)

List<List<Double>> arrayList = new ArrayList<>();
JSONArray jsonArray= new JSONArray(response).getJSONArray(0);

for(int i=0; i<jsonArray.length(); i++) {
    JsonArray nestedArray = jsonArray.get(i);
    List<Double> nestedList = new ArrayList<>();
    for(int j=0; j< nestedArray.length(); j++) {
        nestedList.add(nestedArray.getDouble(j));
    }
    arrayList.add(nestedList);
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use Gson with a class like this to parse your array of arrays of arrays:

public class Example extends ArrayList<ArrayList<ArrayList<Double>>> {}

3 Comments

For some reason you think I would just post an answer without testing.
Many people post many things without testing. Unless indicated otherwise, I normally assume it was not tested. Anyway I was just curious
You should check this one, It has the same principle. I already had to parse a JSON Array with this format at work, so I already tested it irl. stackoverflow.com/questions/13736122/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.