Skip to content

Instantly share code, notes, and snippets.

@manishkpr
Last active August 31, 2015 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manishkpr/2547991867de0d6dbfbb to your computer and use it in GitHub Desktop.
Save manishkpr/2547991867de0d6dbfbb to your computer and use it in GitHub Desktop.
Adding or Appending JsonObject to Jsonarray in java
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