public Writer write ( Writer writer , int indentFactor , int indent ) throws JSONException { try { boolean commanate = false ; int length = this . length ( ) ; writer . write ( ' ' ) ; if ( length == 1 ) { try { JSONObject . writeValue ( writer , this . myArrayList . get ( 0 ) , indentFactor , indent ) ; } catch ( Exception e ) { throw new JSONException ( "Unable to write JSONArray value at index: 0" , e ) ; } } else if ( length != 0 ) { final int newindent = indent + indentFactor ; for ( int i = 0 ; i < length ; i += 1 ) { if ( commanate ) { writer . write ( ' ' ) ; } if ( indentFactor > 0 ) { writer . write ( ' ' ) ; } JSONObject . indent ( writer , newindent ) ; try { JSONObject . writeValue ( writer , this . myArrayList . get ( i ) , indentFactor , newindent ) ; } catch ( Exception e ) { throw new JSONException ( "Unable to write JSONArray value at index: " + i , e ) ; } commanate = true ; } if ( indentFactor > 0 ) { writer . write ( ' ' ) ; } JSONObject . indent ( writer , indent ) ; } writer . write ( ' ' ) ; return writer ; } catch ( IOException e ) { throw new JSONException ( e ) ; } }
Write the contents of the JSONArray as JSON text to a writer .