Last active
August 31, 2015 06:08
-
-
Save manishkpr/2547991867de0d6dbfbb to your computer and use it in GitHub Desktop.
Adding or Appending JsonObject to Jsonarray in java
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
String jsonData = "{\"results\":[{\"lat\":\"value\",\"lon\":\"value\" }]}"; | |
System.out.println(jsonData); | |
try { | |
JSONArray result = new JSONObject(jsonData).getJSONArray("results"); | |
result.getJSONObject(0).put("city","Singapore"); | |
jsonData = "{\"results\":"+result.toString()+"}"; | |
System.out.println(jsonData); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment