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

Writer net::sf::json::JSONArray::write ( Writer  writer  )  [inline]

Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.

Warning: This method assumes that the data structure is acyclical.

Returns:
The writer.
Exceptions:
JSONException 

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

Definition at line 2467 of file JSONArray.java.

References elements, and size().

                                        {
      try{
         boolean b = false;
         int len = size();

         writer.write( '[' );

         for( int i = 0; i < len; i += 1 ){
            if( b ){
               writer.write( ',' );
            }
            Object v = this.elements.get( i );
            if( v instanceof JSONObject ){
               ((JSONObject) v).write( writer );
            }else if( v instanceof JSONArray ){
               ((JSONArray) v).write( writer );
            }else{
               writer.write( JSONUtils.valueToString( v ) );
            }
            b = true;
         }
         writer.write( ']' );
         return writer;
      }catch( IOException e ){
         throw new JSONException( e );
      }
   }


Generated by  Doxygen 1.6.0   Back to index