【问题标题】:How to make JSONArray empty or delete it如何使 JSONArray 为空或删除它
【发布时间】:2012-04-09 09:02:01
【问题描述】:

完成一个活动的执行后,我想让 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"}]}]

【问题讨论】:

    标签: android json


    【解决方案1】:

    构建JSON数组后,将JSONArray对象无效化。下次再构建JSON数组

    【讨论】:

      【解决方案2】:

      已回复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);
      

      【讨论】:

        猜你喜欢
        • 2017-05-18
        • 2012-02-03
        • 1970-01-01
        • 1970-01-01
        • 2023-04-07
        • 1970-01-01
        • 2012-02-07
        • 2014-01-08
        • 1970-01-01
        相关资源
        最近更新 更多