public interface JSONWriter extends Flushable, Closeable
final JSONStreams json = ...; // acquire the JSONStreams service
final Appendable output = ...; // create a stream to write to
...
final JSONWriter writer = json.jsonWriter(output);
writer.startObject().property("foo","bar").endObject(); //writes: {"foo":"bar"}
final JSONStreams json = ...; // acquire the JSONStreams service
final Appendable output = ...; // create a stream to write to
...
final JSONWriter writer = json.jsonWriter(output);
writer.startObject()
.propertyName("nested")
.startObject()
.property("foo","bar")
.endObject()
.endObject(); //writes: {"nested":{"foo":"bar"}}
final JSONStreams json = ...; // acquire the JSONStreams service
final Appendable output = ...; // create a stream to write to
...
final JSONWriter writer = json.jsonWriter(output);
writer.startObject()
.propertyName("items")
.startArray()
.value("first")
.value("second")
.nullValue()
.endObject()
.endObject(); //writes: {"items":["first","second",null]}
| Modifier and Type | Method and Description |
|---|---|
JSONWriter |
append(JSONToken token)
Write a
JSONToken instance to the stream. |
JSONWriter |
endArray()
End an array, emit the closing square bracket (
]). |
JSONWriter |
endObject()
End an object, emit the closing brace (
}). |
JSONWriter |
nullValue()
Emit a null property value.
|
JSONWriter |
property(String name, CharSequence value)
Emit a property with a textual value.
|
JSONWriter |
propertyName(String name)
Emit the name of a property
|
JSONWriter |
startArray()
Start an array, emit the opening square bracket(
[) |
JSONWriter |
startObject()
Start an object, emit the opening brace (
{). |
JSONWriter |
value(Boolean value)
Emit a boolean value, mapping it to the unquoted values:
true or false |
JSONWriter |
value(CharSequence value)
Emit a textual value, quoting and escaping the string
|
JSONWriter |
value(Number value)
Emit a numeric value.
|
JSONWriter |
value(Readable value)
Emit a textual value, quoting and escaping the string.
|
JSONWriter append(JSONToken token) throws JSONIOException
JSONToken instance to the stream.token - The token to writeJSONIOException - if an IO error occursJSONWriter endObject() throws JSONIOException
}).JSONIOException - if an IO error occursJSONWriter endArray() throws JSONIOException
]).JSONIOException - if an IO error occursJSONWriter propertyName(String name) throws JSONIOException
name - The name of the propertyJSONIOException - if an IO error occursJSONWriter property(String name, CharSequence value) throws JSONIOException
name - Name of the propertyvalue - The value of the propertyJSONIOException - if an IO error occursJSONWriter startObject() throws JSONIOException
{).JSONIOException - if an IO error occursJSONWriter startArray() throws JSONIOException
[)JSONIOException - if an IO error occursJSONWriter value(Boolean value) throws JSONIOException
true or falsevalue - boolean valueJSONIOException - if an IO error occursJSONWriter value(CharSequence value) throws JSONIOException
value - textual valueJSONIOException - if an IO error occursJSONWriter value(Number value) throws JSONIOException
value - Numeric valueJSONIOException - if an IO error occursJSONWriter value(Readable value) throws JSONIOException
value - textual valueJSONIOException - if an IO error occursJSONWriter nullValue() throws JSONIOException
JSONIOException - if an IO error occurs