java处理JSON格式数据的常用技术(一)


java处理JSON格式数据的常用技巧

   public static String[] getStringArray4Json(String jsonString)...{
         
       JSONArray jsonArray = JSONArray.fromObject(jsonString);
       String[] stringArray = new String[jsonArray.size()];
       for( int i = 0 ; i
           stringArray[i] = jsonArray.getString(i);
           
        }
       
       return stringArray;
    }
   
    public static Long[] getLongArray4Json(String jsonString)...{
        
        JSONArray jsonArray = JSONArray.fromObject(jsonString);
       Long[] longArray = new Long[jsonArray.size()];
       for( int i = 0 ; i
            longArray[i] = jsonArray.getLong(i);
        }
       return longArray;
     }
    
   
   public static Integer[] getIntegerArray4Json(String jsonString)...{
        
          JSONArray jsonArray = JSONArray.fromObject(jsonString);
        Integer[] integerArray = new Integer[jsonArray.size()];
       for( int i = 0 ; i
            integerArray[i] = jsonArray.getInt(i);
            
         }
        return integerArray;
    }
    
   
    public static Date[] getDateArray4Json(String jsonString,String DataFormat)...{
        
         JSONArray jsonArray = JSONArray.fromObject(jsonString);
         Date[] dateArray = new Date[jsonArray.size()];
         String dateString;
        Date date;
        
        for( int i = 0 ; i
             dateString = jsonArray.getString(i);
             date = DateUtil.stringToDate(dateString, DataFormat);
            dateArray[i] = date;
           
       }
        return dateArray;
    }


你可能感兴趣的:(java,json)