Reputation: 481
Just a quick question:
If I have a json object which contains "key/value"s like this:
"name":"value"
and I want to change the name parts to something else, what should I do? I don't want to remove and make it again.
Upvotes: 4
Views: 17392
Reputation: 39406
Proper and compact implementation, given that jsonObject
is the json object you are referring to and it is an instance of JSONObject
:
jsonObject.put("new name", jsonObject.remove("name"));
Upvotes: 13
Reputation: 20500
Create a new object with the new value
new JSONObject(jsonobject.toString().replace("\"name\":","\"newvalue\":");)
Upvotes: 0