Updating the elements in the JSON

suggest change

sample json to update

"student":{"name":"Rahul", "lastname":"sharma"},

To update the elements value in the json we need to assign the value and update.

try {
    // Create a new instance of a JSONObject
    final JSONObject object = new JSONObject(jsonString);
    JSONObject studentJSON = object.getJSONObject("student");


    // Calling toString() on the JSONObject returns the JSON in string format.
    final String json = object.toString();
} catch (JSONException e) {
    Log.e(TAG, "Failed to create JSONObject", e);

updated value

"student":{"name":"Kumar", "lastname":"sharma"},

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents