json remove the spaces before and after the value of value

    / ** 
    * @Title: JsonStrTrim 
    * @author : JSW 
    * @date: 2012-12-7 
    * @time: 09:19:18 AM 
    * @Description: Incoming string type of place json string string property blank value 
    * @param jsonStr 
    * @return 
    * for @exception :( exception description)
     * / 
    public the jSONObject JsonStrTrim (String jsonStr) { 
        
        the jSONObject reagobj = JSONObject.fromObject (jsonStr);
         // remove jsonObject space values in fields 
        Iterator = ITT reagobj.keys (); 
        
        the while (itt.hasNext ()) { 
            
            String Key = itt.next().toString();
            String value = reagobj.getString(key);
            
            if(value == null){                
                continue ;        
            }else if("".equals(value.trim())){                
                continue ;
            }else{
                reagobj.put(key, value.trim());
            }
        }
        return reagobj;
    }
    
    /**
    * @Title: JsonStrTrim
    * @author : jsw
    * @date : 2012-12-7
    * @Time: 09:21:48 AM 
    * @Description: Incoming jsonObject removal for spaces 
    * @param jsonStr 
    * @return 
    * @exception :( exception description)
     * / 
    public JSONObject JsonStrTrim (JSONObject jsonStr) { 
        
        JSONObject reagobj = jsonStr ;
         // takes a value in a field jsonObject spaces 
        the Iterator ITT = reagobj.keys (); 
        
        the while (itt.hasNext ()) { 
            
            String Key = itt.next () toString ();. 
            String value = reagobj.getString ( Key); 
            
            IF (value == null) {                
                 Continue ;         
            } the else  IF ( "" .equals (value.trim ())) {                
                 Continue ; 
            } the else { 
                reagobj.put (Key, value.trim ()); 
            } 
        } 
        return reagobj; 
    } 
    
    
    / ** 
    * @ the Title: JsonStrTrim 
    * @author : JSW 
    * @date: 2012-12-7 
    * @time: 11:48:59 aM 
    * @Description: the values before and after the value of the place jsonarry jsonObject spaces 
    * @param arr 
    * @return
    * For @exception :( exception description)
     * / 
    public the JSONArray JsonStrTrim (the JSONArray ARR) { 
        
        IF (ARR =! Null && arr.size ()> 0 ) {
             for ( int I = 0; I <arr.size (); I ++ ) { 
                
                the jSONObject obj = (the jSONObject) arr.get (I);
                 // takes a value in a field jsonObject spaces 
                the Iterator ITT = obj.keys (); 
                
                the while (itt.hasNext ()) { 
                    
                    String Key = itt.next () .toString (); 
                    String value = obj.getString (Key); 
                    
                    IF (value == null){                
                        continue ;        
                    }else if("".equals(value.trim())){                
                        continue ;
                    }else{
                        obj.put(key, value.trim());
                    }
                }
                arr.set(i,  obj );                
            }
        }
        return arr;

 

Guess you like

Origin www.cnblogs.com/yuanchaoyong/p/10953756.html