How can I update a JSON data in Android. I get several data sets and I want to change one. How can I do this?
Asked
Active
Viewed 1.4k times
0
-
So, What you have try ? – Nirav Ranpara Mar 28 '13 at 07:39
-
you question is unclear,please explain more – Saad Asad Mar 28 '13 at 07:39
-
Have you tried anything so far? Can you post some of your code so we can see what might be problematic? – richsage Mar 28 '13 at 07:41
2 Answers
4
You can easily override the value
you want, simply putting the same Object
(key, value pair with the same key and different value) again in the JSONObject
.
E.g:-
String jsonStr = "{\"a\" = 1, \"b\" = 2}";
try {
JSONObject json = new JSONObject(jsonStr);
json.put("a", 3);
} catch (JSONException e) {}
Modify this as per your needs and JSON
structure.

Rahul
- 44,383
- 11
- 84
- 103
0
You can take reference from
http://www.vogella.com/articles/AndroidJSON/article.html#androidjson_write
public void writeJSON() {
JSONObject object = new JSONObject();
try {
object.put("name", "Jack Hack");
object.put("score", new Integer(200));
object.put("current", new Double(152.32));
object.put("nickname", "Hacker");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println(object);
}

Vipul
- 27,808
- 7
- 60
- 75