一个java处理JSON格式数据的通用类(二)

/** *//**
      * 从json数组中解析出java字符串数组
      * @param jsonString
      * @return
     */
    public static String[] getStringArray4Json(String jsonString)...{
        
         JSONArray jsonArray = JSONArray.fromObject(jsonString);
         String[] stringArray = new String[jsonArray.size()];
        for( int i = 0 ; i<jsonArray.size() ; i++ )...{
             stringArray[i] = jsonArray.getString(i);
            
         }
        
        return stringArray;
     }
    
    /** *//**
      * 从json数组中解析出javaLong型对象数组
      * @param jsonString
      * @return
     */
    public static Long[] getLongArray4Json(String jsonString)...{
        
         JSONArray jsonArray = JSONArray.fromObject(jsonString);
         Long[] longArray = new Long[jsonArray.size()];
        for( int i = 0 ; i<jsonArray.size() ; i++ )...{
             longArray[i] = jsonArray.getLong(i);
            
         }
        return longArray;
     }
    
    /** *//**
      * 从json数组中解析出java Integer型对象数组
      * @param jsonString
      * @return
     */
    public static Integer[] getIntegerArray4Json(String jsonString)...{
        
         JSONArray jsonArray = JSONArray.fromObject(jsonString);
         Integer[] integerArray = new Integer[jsonArray.size()];
        for( int i = 0 ; i<jsonArray.size() ; i++ )...{
             integerArray[i] = jsonArray.getInt(i);
            
         }
        return integerArray;
     }
    
    /** *//**
      * 从json数组中解析出java Date 型对象数组,使用本方法必须保证
      * @param jsonString
      * @return
     */
    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<jsonArray.size() ; i++ )...{
             dateString = jsonArray.getString(i);
             date = DateUtil.stringToDate(dateString, DataFormat);
             dateArray[i] = date;
            
         }
        return dateArray;
     }

posted @ 2013-05-30 15:14  Struts-pring  阅读(177)  评论(0编辑  收藏  举报