完成活动的执行后,我想让jSONArray为空或删除它。因为当我反复调用活动时,新数据会附加到JSONArray中的旧数据。我的jsonArray如下所示..
[{"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"}]}]
答案 0 :(得分:0)
已回答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);
答案 1 :(得分:0)
构建JSON
数组后,使JSONArray
对象无效。下次再次构建JSON
数组