JSONObject remove empty value pairs

前端 未结 6 1075
暖寄归人
暖寄归人 2021-01-05 09:06

Here is my Json File:

{  
   \"models\":{},
   \"path\":[  
      {  
         \"path\":\"/web-profiles\",
         \"operations\":[  
            {  
               


        
6条回答
  •  执念已碎
    2021-01-05 09:36

    This should do the trick::

                            Iterator keys = jsonObject.keys();
                            while(keys.hasNext()) {
                                String key = keys.next();
                                boolean propertyValuePresent = jsonObject.get(key) != null 
                                && jsonObject.get(key)!="null"
                                && !jsonObject.get(key).toString().isEmpty();     
                                if(propertyValuePresent){
                                    jsonObject.remove(key);
                                }
                            }
    

提交回复
热议问题