从JSONArray中删除JSON对象 – Jettison

是否有通过使用索引删除存储在JSONArray中的JSONObject的直接方法。 我尝试了所有的可能性。 仍然无法从JSON数组中删除JSON对象。 任何提示都会有所帮助谢谢

在java-json中,没有直接的方法来删除jsonObject,但是使用json-simple ,这样做很简单:

JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); JSONObject jsonObject1 = new JSONObject(); JSONObject jsonObject2 = new JSONObject(); jsonObject.put("key1", "value1"); jsonObject1.put("key2", "value2"); jsonObject2.put("key3", "value3"); jsonArray.add(jsonObject); jsonArray.add(jsonObject1); jsonArray.add(jsonObject2); //........ Whole Json Array System.out.println(jsonArray); //To remove 2nd jsonObject (index starts from 0) jsonArray.remove(1); // Now the array will not have 2nd Object System.out.println(jsonArray); 

只需获取json数组中JSON对象的索引

并通过array.splice(index,howmany,item1,…..,itemX)方法删除json对象

有关更多信息,请使用此链接http://www.w3schools.com/jsref/jsref_splice.asp