Logo Search packages:      
Sourcecode: libjson-java version File versions

static List net::sf::json::JSONArray::toList ( JSONArray  jsonArray,
Object  root,
JsonConfig  jsonConfig 
) [inline, static]

Creates a List from a JSONArray.

Definition at line 654 of file JSONArray.java.

References get(), net::sf::json::JsonConfig::getNewBeanInstanceStrategy(), net::sf::json::util::NewBeanInstanceStrategy::newInstance(), size(), and toList().

                                                                                        {
      if( jsonArray.size() == 0 || root == null ){
         return new ArrayList();
      }

      List list = new ArrayList();
      int size = jsonArray.size();
      for( int i = 0; i < size; i++ ){
         Object value = jsonArray.get( i );
         if( JSONUtils.isNull( value ) ){
            list.add( null );
         }else{
            Class type = value.getClass();
            if( JSONArray.class.isAssignableFrom( type ) ){
               list.add( toList( (JSONArray) value, root, jsonConfig ) );
            }else if( String.class.isAssignableFrom( type )
                  || Boolean.class.isAssignableFrom( type ) || JSONUtils.isNumber( type )
                  || Character.class.isAssignableFrom( type )
                  || JSONFunction.class.isAssignableFrom( type ) ){
               list.add( value );
            }else{
               try{
                  Object newRoot = jsonConfig.getNewBeanInstanceStrategy()
                        .newInstance( root.getClass(), null );
                  list.add( JSONObject.toBean( (JSONObject) value, newRoot, jsonConfig ) );
               }catch( JSONException jsone ){
                  throw jsone;
               }catch( Exception e ){
                  throw new JSONException( e );
               }
            }
         }
      }
      return list;
   }


Generated by  Doxygen 1.6.0   Back to index