Created
November 13, 2014 12:02
-
-
Save devrath/7121bb9ebdbbe310e959 to your computer and use it in GitHub Desktop.
Parsing JSON using GSON parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Refered Link: http://stackoverflow.com/questions/5490789/json-parsing-using-gson-for-java | |
// Refered Link: http://stackoverflow.com/a/10593838/1083093 | |
JSONObject refJson; | |
JSONArray jsonarray= null; | |
JsonElement gsonJelement; | |
JsonObject gsonJobject; | |
try { | |
// Retrieve JSON Objects from the given URL address | |
refJson = JSONfunctions.getJSONfromURL(url.trim()); | |
gsonJelement = new JsonParser().parse(refJson.toString()); | |
gsonJobject = gsonJelement.getAsJsonObject(); | |
gsonJobject = gsonJobject.getAsJsonObject("locations"); | |
refJson = new JSONObject(gsonJobject.toString().trim()); | |
Iterator<?> keys = refJson.keys(); | |
while( keys.hasNext() ){ | |
String key = (String)keys.next(); | |
//jsonobject=jsonObj.getAsJsonObject("locations"); | |
gsonJelement = new JsonParser().parse(refJson.toString()); | |
gsonJobject = gsonJelement.getAsJsonObject(); | |
gsonJobject = gsonJobject.getAsJsonObject(key); | |
refJson = new JSONObject(gsonJobject.toString().trim()); | |
String refLatitude=refJson.getString("latitude"); | |
String refLongitude=refJson.getString("longitude"); | |
} | |
} catch (JsonSyntaxException e) { | |
e.printStackTrace(); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment