Marcel
Marcel

Reputation: 2184

GSON parse Array in array in array

I face this problem, from the API I'm getting an extens JSON with one object called coordinates, this object is an array that includes an array o array.

To be more clear look at this example:

"coordinates": [
                [
                    [
                        -0.087118,
                        51.508823
                    ]

Or in this pic you can see it better

Or in this pic you can see it better

So now I'm trying to parse it using GSON and I'm not being success. Can anyone give me an idea how to create the class for this?

Thank you

Upvotes: 1

Views: 368

Answers (2)

SteBra
SteBra

Reputation: 4247

I can give you an example, where you wouldn't use Gson, but you'll get the idea. Lets say that you put your JSON responce in a String called json

String json = ""coordinates": [[[-0.087118,51.508823]";

JSONArray firstArray = new JSONArray(json);
         for (int i =0; i < firstArray.length(); i++){

          JSONArray secondArray = firstArray.getJSONArray(i);
          for (int j =0; i < secondArray.length(); j++){

               JSONArray thirdArray = secondArray.JSONArray(j);
               for (int q =0; i < thirdArray.length(); q++){

                int x = thirdArray.getInteger("0");
                int y = thirdArray.getInteger("1");
               }
            }
  }

Upvotes: 0

reactivemobile
reactivemobile

Reputation: 505

public class Coordinate extends ArrayList<Arraylist<Arraylist<float>>>{
}

Upvotes: 5

Related Questions