0

After completion of execution of an activity i want to make jSONArray empty or delete it. Because when i am calling the activity repeatedly the new data gets append to the old data present in JSONArray. My jsonArray is as shown below..

[{"record":[
            {......},
            {.......}
           ]
 },
 {"record":[
            {..........},
            {.........}
           ]
 }
] 


First time:
[{"record":[{"intensity":"Low","Body_SubParts":"Scalp","symptom":"Bleeding"}]}]

Second time:
[{"record":[{"intensity":"Low","Body_SubParts":"Scalp","symptom":"Bleeding"},
{"intensity":"Low","Body_SubParts":"Eyes","symptom":"Bleeding"}]}]

2 Answers2

0

Answered here

// Assuming you have constructed the replacement as
JSONObject jsonArray11_obj2 = new JSONObject();
jsonArray11_obj2.put("intensity", "high");
jsonArray11_obj2.put("Body_SubParts", "Scalp");
// ...

// Then the code doing the replacement would look similar to
int index = 0;
((JSONObject)jsonArray.get(index)).getJSONArray("record").put(0, jsonArray11_obj2);
Community
  • 1
  • 1
user799188
  • 13,965
  • 5
  • 35
  • 37
0

After building the JSON array, nullify the JSONArray object..Next time again build the JSON Array

Vamshi
  • 1,495
  • 1
  • 15
  • 31