Lets say I gave a JSONObject
{ "person":{"name":"Sam", "surname":"ngonma"}, "car":{"make":"toyota", "model":"yaris"} }
How do I update some of the values in the JSONObject?
Like below :
String name = jsonArray.getJSONObject(0).getJSONObject("person").getString("name"); name = "Sammie";
Use the put method: https://developer.android.com/reference/org/json/JSONObject.html
JSONObject person = jsonArray.getJSONObject(0).getJSONObject("person"); person.put("name", "Sammie");
Remove key and then add again the modified key, value pair as shown below :
JSONObject js = new JSONObject(); js.put("name", "rai"); js.remove("name"); js.put("name", "abc");
I haven't used your example; but conceptually its same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With