Reputation: 2402
Hi i want to change/alter value of a string inside a json object which inside a JSONArray and which is from a file stored in internal storage.
My initial thoughts are to convert the object to a string do a find a replace and convert back to JSONObject
search the JSONArray
for the JSONObject remove the old one and put the new one in. Then save the array as a .JSON File to internal storage (will this replace the file thats already there or will it create another file with the same name?).
This is my initial thoughts on how to do this but is this the correct way or is there easier more efficient way to do this?
Upvotes: 1
Views: 8932
Reputation: 8106
Depends on the library you are using for parsing JSON. Some do allow code like jsonOArray.get("jsonObject").put("key", "val");
Some require to obtain the object first then do something like
JsonObj = jsonArray.get("jsonObject"); jsonObj.putVal("key", "val");
Which library do you use for processing json?
Upvotes: 0
Reputation: 1628
try using this :
nameValuePairs.add(new BasicNameValuePair("cus_id", cus_id));
getting data in this:
JSONObject json = new JSONObject(responseString);
JSONArray jArray = json.getJSONArray("customer");
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
cus_points = json_data.getString("cus_points");
Upvotes: 0
Reputation: 16354
First, you need to retrieve the required JSON Object form the JSON Array.
You can update the key-value pair of your JSON Object directly by using
mJsonObj.put("<key>", <value>)
.
Upvotes: 4