美文网首页
Android报错:调用JSONArray.remove ()报

Android报错:调用JSONArray.remove ()报

作者: 梦工厂 | 来源:发表于2015-08-30 22:21 被阅读1189次

JSONArray的remove方法是在API level 19时加入的,在低版本调用时会出现错误。

VFY: unable to resolve virtual method 9294: Lorg/json/JSONArray;.remove (I)Ljava/lang/Object;```
解决方法:
``` java
public JSONArray remove(JSONArray jsonArray,int index){ 
             JSONArray mJsonArray  = new JSONArray();

             if(index<0)    return mJsonArray;
             if(index>jsonArray.length())   return mJsonArray;

             for( int i=0;i<index;i++){
                try {
                    mJsonArray.put(jsonArray.getJSONObject(i));
                    } catch (JSONException e) {
                            e.printStackTrace();
                    }
                }   

             for( int i=index+1;i< jsonArray.length();i++){
                try {
                    mJsonArray.put(jsonArray.getJSONObject(i));
                    } catch (JSONException e) {
                            e.printStackTrace();
                    }
                 }
             return mJsonArray;
}

相关文章

网友评论

      本文标题:Android报错:调用JSONArray.remove ()报

      本文链接:https://www.haomeiwen.com/subject/lrakcttx.html