-2
{
"type":
    "coll",
         "locations":[
                 {"geometry":
                         {"Coords":
                                 [54.7,46.7]
                         }
                 },
                 {"geometry":
                         {"Coords":
                                 [54.7,46.7]
                         }
                 },
                 {"geometry":
                         {"Coords":
                                 [54.7,46.6]
                         }
                 },
                 {"geometry":
                         {"Coords":
                                 [54.64999833333333,46.6]
                         }
                 }
         ]
}
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • What programming language? – Willem Van Onsem May 10 '17 at 10:31
  • Java. Should have mentioned that, sorry. – Craig Navin May 10 '17 at 10:33
  • Okay. What research have you done? What has [searching](/help/searching) found for you? Where, specifically, are you stuck? What does your code trying to do this based on your research look like? – T.J. Crowder May 10 '17 at 10:35
  • I'm looking for an answer similar to the answer on this post. http://stackoverflow.com/questions/27009768/get-latitude-and-longitude-from-json-data I just cant get my head around how deep i would need to go with getJSONObject() before i would need to getJSONArray(). – Craig Navin May 10 '17 at 10:36

1 Answers1

0

In java using json.simple,here the code: Here i assume the json data is present in file.json

  Object obj = parser.parse(new FileReader( "file.json" ));
  JSONObject jsonObject = (JSONObject) obj;
   JSONArray loc= (JSONArray) jsonObject.get("locations");
    Iterator i = loc.iterator();


     while (i.hasNext()) {
    JSONObject geo   = (JSONObject) (i.next());

    JSONObject coords   = (JSONObject)geo.get("geometry");
    String coord= (String)coords.get("Coords");
        System.out.println(coord);
    }
Vishesh
  • 308
  • 1
  • 9