1

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

3
  • The text example is not consistent with the picture Commented Nov 4, 2014 at 15:30
  • why not? because of the numbers? in the pic I'm using Json editor chrome extension. Anyways it's solved now Commented Nov 6, 2014 at 7:43
  • From the text example it's not clear if it's [[[x,y],[x,y]...]] or [[[x,y]],[[x,y]],...] Commented Nov 6, 2014 at 7:45

2 Answers 2

5
public class Coordinate extends ArrayList<Arraylist<Arraylist<float>>>{
}
Sign up to request clarification or add additional context in comments.

1 Comment

Then say coordinate.get(0).get(0).get(0) etc
0

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");
               }
            }
  }

1 Comment

thanks for the approach but there answer of @reactivemobile works

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.