Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSONArray remove在JAVA中找不到符号错误_Java_Json_Arrays - Fatal编程技术网

JSONArray remove在JAVA中找不到符号错误

JSONArray remove在JAVA中找不到符号错误,java,json,arrays,Java,Json,Arrays,[说明] 1.使用Java 2.使用org.json.JSONArray和org.json.JSONObject [问题] 当我调用JSONArray的remove()方法时,在编译我的项目时,总是获取“找不到符号:方法删除(int)”,有什么帮助吗 这里有一个类似的问题: 但答案似乎不正确,因为这只会删除内部JSONObject的键值对,而不会删除整个InInde JSONObject 示例代码: JSONArray test_arr = new JSONArray("[{'id':'1',

[说明]
1.使用Java
2.使用org.json.JSONArray和org.json.JSONObject
[问题]
当我调用JSONArray的
remove()
方法时,在编译我的项目时,总是获取“找不到符号:方法删除(int)”,有什么帮助吗

这里有一个类似的问题:
但答案似乎不正确,因为这只会删除内部JSONObject的键值对,而不会删除整个InInde 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.

提前感谢您的帮助。

好吧,有趣的是,Maven central中最新的org.json JAR确实包含一个
JSONArray
类,该类没有删除方法。这是从json-20090211.jar中提取的类上的javap摘录:

public org.json.JSONArray put(int, long) throws org.json.JSONException;
public org.json.JSONArray put(int, java.util.Map) throws org.json.JSONException;
public org.json.JSONArray put(int, java.lang.Object) throws org.json.JSONException;
public org.json.JSONObject toJSONObject(org.json.JSONArray) throws org.json.JSONException;
public java.lang.String toString();
public java.lang.String toString(int) throws org.json.JSONException;
java.lang.String toString(int, int) throws org.json.JSONException;
public java.io.Writer write(java.io.Writer) throws org.json.JSONException;
此编译代码与中提供的不一致,因此我将不使用它。该库非常简单,我建议您只需自己获取源代码,然后:

  • 把它编译成一个罐子
  • 将其直接包含到您的项目中

您是否正在使用(比如)旧版本的lib,但没有该特定方法?[检查此项][1]它可能会对您有所帮助。。。使用名称值[1]删除json数组:[对Brian]我检查了我使用的jar文件,它确实有删除方法。[对Pratik]谢谢,但我说我使用的是java,不是javascript.Hmmm,
remove(int)
方法自发布以来就一直在代码库中。这一定是您在如何将代码包含到项目中的错误。[对Perception]我使用java,因此==>在库路径中包含“org.json.jar”,在代码中包含“import org.json.JSONArray;”。这个类的其他函数在我的项目中运行良好,但只有这个remove()函数。谢谢。在我的项目中,我反编译org.json.jar,它确实有一个remove()方法。不知道为什么会出现“找不到符号”错误。现在我使用ArrayList而不是JSONArray,然后我可以使用ArrayList的remove()方法。再次感谢您的帮助和建议。