首先假设有这么一个JSONArray
JSONArray Array1;
JSONArray ITEM = new JSONArray();
name为你获取要删除的字段名称,IETM就是你删除后得到的新的JSONArray数组了
String name = null; try { name = orderDish.getString("name"); JSONObject odItems = null; for(int j=0;j<Array1.length();j++) { odItems = (JSONObject)Array1.get(j); if(name.equals(odItems.getString("name"))) { Array1.put(j, null); // continue; } else { newItems.put(odItems); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); }
同理,替换就是直接把要替换的给put进去就行了。