How do I remove a specific element from a JSONArray?

后端 未结 9 1751
执笔经年
执笔经年 2020-11-29 08:18

I am building one app in which I request a PHP file from server. This PHP file returns a JSONArray having JSONObjects as its elements e.g.,

[ 
  {
           


        
9条回答
  •  醉梦人生
    2020-11-29 08:47

    In my case I wanted to remove jsonobject with status as non zero value, so what I did is made a function "removeJsonObject" which takes old json and gives required json and called that function inside the constuctor.

    public CommonAdapter(Context context, JSONObject json, String type) {
            this.context=context;
            this.json= removeJsonObject(json);
            this.type=type;
            Log.d("CA:", "type:"+type);
    
        }
    
    public JSONObject removeJsonObject(JSONObject jo){
            JSONArray ja= null;
            JSONArray jsonArray= new JSONArray();
            JSONObject jsonObject1=new JSONObject();
    
            try {
                ja = jo.getJSONArray("data");
    
            } catch (JSONException e) {
                e.printStackTrace();
            }
            for(int i=0; i

提交回复
热议问题