- public void removeThisGarden(String gardenId){
- try {
- List list = new ArrayList();
- String gardens = SharePreferenceUtil.getStringDataByKe(this,"gardens",null);
- gardenArray = new JSONArray(gardens);
- for (int i = 0;i<gardenArray.length();i++){
- list.add(gardenArray.get(i));
- JSONObject gardenJson = (JSONObject) gardenArray.get(i);
- if (gardenId.equals(gardenJson.getString("gardenId"))){
- list.remove(i);
- }
- gardenArray = new JSONArray(list);
- SharePreferenceUtil.saveStringDataToSharePreference(this,"gardens",gardenArray.toString());
- }
- }catch (JSONException e){
- e.printStackTrace();
- }
- }
删除JSONArray中的某个元素
最新推荐文章于 2024-09-12 17:03:25 发布