【发布时间】:2013-01-31 12:45:52
【问题描述】:
[描述]
1. 使用 Java
2. 使用 org.json.JSONArray 和 org.json.JSONObject
[问题]
当我调用 JSONArray 的 remove() 方法时,编译我的项目时总是得到“找不到符号:方法删除(int)”,有什么帮助吗?
这是一个类似的问题:How to remove JSONArray element using Java
但答案似乎不正确,因为这只会删除内部 JSONObject 的键值对,而不是整个内部 JSONObject。
示例代码:
JSONArray test_arr = new JSONArray("[{'id':'1', 'name': 'name1'},{'id':'2', 'name':'name2'}]");
test_arr.remove(1); // here will cause the "cannot find symbol" error.
提前感谢您的帮助。
【问题讨论】:
-
您是否在使用(比如说)没有特定方法的旧版本库?
-
[Check this][1] 它可能对您有帮助... 使用名称-值 [1] 删除 json 数组:stackoverflow.com/questions/6310623/…
-
[对 Brian] 我检查了我使用的 jar 文件,它确实有删除方法。 [对 Pratik] 谢谢,但我说我使用的是 java,而不是 javascript。
-
嗯,
remove(int)方法自 very first commit 以来一直在代码库中。这一定是您如何将代码包含到项目中的错误。 -
[to Perception] 我使用java,所以==> 在库路径中包含“org.json.jar”,以及“import org.json.JSONArray;”在代码中。该类的其他函数在我的项目中运行良好,但只有这个 remove() 函数。