private void prepareToPrint() { addIndentation(); addSep(); }
@Override public JSONPrintSession print(String value) { prepareToPrint(); writer.print(value); position = Position.CONTENT; return this; }
/** * Converts this JSON collection into a parsable string representation. * * Warning: This method assumes that the data structure is acyclical. * * Starting in release 5.2, the result will be pretty printed for readability. * * @return a printable, displayable, portable, transmittable representation of the object, beginning with * <code>{</code> <small>(left brace)</small> and ending with <code>}</code> <small>(right * brace)</small>. */ @Override public String toString() { CharArrayWriter caw = new CharArrayWriter(); PrintWriter pw = new PrintWriter(caw); JSONPrintSession session = new PrettyPrintSession(pw); print(session); pw.close(); return caw.toString(); }
@Override public JSONPrintSession printQuoted(String value) { return print(JSONObject.quote(value)); }
/** * Converts this JSON collection into a parsable string representation. * * Warning: This method assumes that the data structure is acyclical. * * Starting in release 5.2, the result will be pretty printed for readability. * * @return a printable, displayable, portable, transmittable representation of the object, beginning with * <code>{</code> <small>(left brace)</small> and ending with <code>}</code> <small>(right * brace)</small>. */ @Override public String toString() { CharArrayWriter caw = new CharArrayWriter(); PrintWriter pw = new PrintWriter(caw); JSONPrintSession session = new PrettyPrintSession(pw); print(session); pw.close(); return caw.toString(); }
@Override public JSONPrintSession printQuoted(String value) { return print(JSONObject.quote(value)); }
private void prepareToPrint() { addIndentation(); addSep(); }
/** * Prints the JSONObject to the write (compactly or not). * * @param writer * to write content to * @param compact * if true, then write compactly, if false, write with pretty printing * @since 5.2.1 */ public void print(PrintWriter writer, boolean compact) { JSONPrintSession session = compact ? new CompactSession(writer) : new PrettyPrintSession(writer); print(session); }
@Override public JSONPrintSession print(String value) { prepareToPrint(); writer.print(value); position = Position.CONTENT; return this; }
@Override public JSONPrintSession printSymbol(char symbol) { addIndentation(); if (symbol != ',') addSep(); writer.print(symbol); return this; }
/** * Prints the JSONObject to the write (compactly or not). * * @param writer * to write content to * @param compact * if true, then write compactly, if false, write with pretty printing * @since 5.2.1 */ public void print(PrintWriter writer, boolean compact) { JSONPrintSession session = compact ? new CompactSession(writer) : new PrettyPrintSession(writer); print(session); }
@Override public JSONPrintSession printSymbol(char symbol) { addIndentation(); if (symbol != ',') addSep(); writer.print(symbol); return this; }