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

String net::sf::json::JSONArray::toString ( int  indentFactor,
int  indent 
) [inline]

Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structure is acyclical.

Parameters:
indentFactor The number of spaces to add to each level of indentation.
indent The indention of the top level.
Returns:
a printable, displayable, transmittable representation of the array.
Exceptions:
JSONException 

Implements net::sf::json::JSON.

Definition at line 2422 of file JSONArray.java.

References size(), and toString().

                                                          {
      int len = size();
      if( len == 0 ){
         return "[]";
      }
      if( indentFactor == 0 ){
         return this.toString();
      }
      int i;
      StringBuffer sb = new StringBuffer( "[" );
      if( len == 1 ){
         sb.append( JSONUtils.valueToString( this.elements.get( 0 ), indentFactor, indent ) );
      }else{
         int newindent = indent + indentFactor;
         sb.append( '\n' );
         for( i = 0; i < len; i += 1 ){
            if( i > 0 ){
               sb.append( ",\n" );
            }
            for( int j = 0; j < newindent; j += 1 ){
               sb.append( ' ' );
            }
            sb.append( JSONUtils.valueToString( this.elements.get( i ), indentFactor, newindent ) );
         }
         sb.append( '\n' );
         for( i = 0; i < indent; i += 1 ){
            sb.append( ' ' );
         }
         for( i = 0; i < indent; i += 1 ){
            sb.insert( 0, ' ' );
         }
      }
      sb.append( ']' );
      return sb.toString();
   }


Generated by  Doxygen 1.6.0   Back to index