有没有一种直接的方法可以通过使用 index.js 删除存储在 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);
关于java - 从 JSONArray 中删除 JSON 对象 - Jettison,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19837532/