public final class JSONObjectBuilder
extends java.lang.Object
JSONStreamReader.
This uses less stack space than parsing via JSONTokener,
since only one stack frame is allocated per nested object or array.
A simple example of how to use this class:
JSONObject jsonObject = JSONObjectBuilder.buildJSONObject(JSON_TEXT);
| Modifier and Type | Method and Description |
|---|---|
static JSONArray |
buildArraySubTree(JSONStreamReader reader)
If the given
JSONStreamReader's ParseState was JSONStreamReader.ParseState.ARRAY,
return the entire subtree as a JSONArray value. |
static <AR> AR |
buildArraySubTree(JSONStreamReader reader,
StructureCollector<?,?,?,AR> collector)
If the given
JSONStreamReader's ParseState was JSONStreamReader.ParseState.ARRAY,
return the entire subtree as an array type, as specified by the given
collector. |
static JSONArray |
buildJSONArray(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
Build a
JSONArray from a InputStream and a supplied
Charset. |
static <AR> AR |
buildJSONArray(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,?,AR> collector)
Build a
JSONArray from a InputStream and a supplied
Charset. |
static JSONArray |
buildJSONArray(JSONStreamReader reader)
Build a
JSONArray from a JSONStreamReader. |
static <AR> AR |
buildJSONArray(JSONStreamReader reader,
StructureCollector<?,?,?,AR> collector)
Build a
JSONArray from a JSONStreamReader. |
static JSONArray |
buildJSONArray(java.io.Reader reader)
Build a
JSONArray from a Reader. |
static <AR> AR |
buildJSONArray(java.io.Reader reader,
StructureCollector<?,?,?,AR> collector)
Build a
JSONArray from a Reader. |
static JSONArray |
buildJSONArray(java.lang.String s)
Build a
JSONArray from a String. |
static <AR> AR |
buildJSONArray(java.lang.String s,
StructureCollector<?,?,?,AR> collector)
Build a
JSONArray from a String. |
static JSONObject |
buildJSONObject(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
Build a
JSONObject from a InputStream and a supplied
Charset. |
static <OR> OR |
buildJSONObject(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,OR,?> collector)
Build a
JSONObject from a InputStream and a supplied
Charset. |
static JSONObject |
buildJSONObject(JSONStreamReader reader)
Build a
JSONObject from a JSONStreamReader. |
static <OR> OR |
buildJSONObject(JSONStreamReader reader,
StructureCollector<?,?,OR,?> collector)
Build a
JSONObject from a JSONStreamReader. |
static JSONObject |
buildJSONObject(java.io.Reader reader)
Build a
JSONObject from a Reader. |
static <OR> OR |
buildJSONObject(java.io.Reader reader,
StructureCollector<?,?,OR,?> collector)
Build a
JSONObject from a Reader. |
static JSONObject |
buildJSONObject(java.lang.String s)
Build a
JSONObject from a String. |
static <OR> OR |
buildJSONObject(java.lang.String s,
StructureCollector<?,?,OR,?> collector)
Build a
JSONObject from a String. |
static java.lang.Object |
buildJSONValue(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
Build a JSON value from a
InputStream and supplied
Charset. |
static java.lang.Object |
buildJSONValue(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,?,?> collector)
Build a JSON value from a
InputStream and supplied
Charset. |
static java.lang.Object |
buildJSONValue(JSONStreamReader reader)
Build a JSON value from a
JSONStreamReader. |
static java.lang.Object |
buildJSONValue(JSONStreamReader reader,
StructureCollector<?,?,?,?> collector)
Build a JSON value from a
JSONStreamReader. |
static java.lang.Object |
buildJSONValue(java.io.Reader reader)
Build a JSON value from a
Reader. |
static java.lang.Object |
buildJSONValue(java.io.Reader reader,
StructureCollector<?,?,?,?> collector)
Build a JSON value from a
Reader. |
static java.lang.Object |
buildJSONValue(java.lang.String s)
Build a JSON value from a
String. |
static java.lang.Object |
buildJSONValue(java.lang.String s,
StructureCollector<?,?,?,?> collector)
Build a JSON value from a
String. |
static JSONObject |
buildObjectSubTree(JSONStreamReader reader)
If the given
JSONStreamReader's ParseState was JSONStreamReader.ParseState.OBJECT,
return the entire subtree as a JSONObject value. |
static <OR> OR |
buildObjectSubTree(JSONStreamReader reader,
StructureCollector<?,?,OR,?> collector)
If the given
JSONStreamReader's ParseState was JSONStreamReader.ParseState.OBJECT,
return the entire subtree as an object type, as specified by the given
collector. |
public static java.lang.Object buildJSONValue(java.io.Reader reader)
throws JSONException
Reader. The value may be one of:
JSONObject.NULLBoolean.TRUE or Boolean.FALSEDouble, Long, Integer,
BigDecimal, or BigIntegerStringJSONObjectJSONArrayreader - A reader.JSONExceptionpublic static java.lang.Object buildJSONValue(java.io.Reader reader,
StructureCollector<?,?,?,?> collector)
throws JSONException
Reader. The value may be one of:
Boolean.TRUE or Boolean.FALSEDouble, Long, Integer,
BigDecimal, or BigIntegerStringreader - A reader.collector - A collector object for creating structuresJSONExceptionpublic static java.lang.Object buildJSONValue(java.io.InputStream inputStream,
java.nio.charset.Charset charset)
throws JSONException
InputStream and supplied
Charset. The value may be one of:
JSONObject.NULLBoolean.TRUE or Boolean.FALSEDouble, Long, Integer,
BigDecimal, or BigIntegerStringJSONObjectJSONArrayinputStream - the input stream containing the JSON datacharset - the character set with which to interpret the
input streamJSONExceptionpublic static java.lang.Object buildJSONValue(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,?,?> collector)
throws JSONException
InputStream and supplied
Charset. The value may be one of:
Boolean.TRUE or Boolean.FALSEDouble, Long, Integer,
BigDecimal, or BigIntegerStringinputStream - the input stream containing the JSON datacharset - the character set with which to interpret the
input streamcollector - A collector object for creating structuresJSONExceptionpublic static java.lang.Object buildJSONValue(java.lang.String s)
throws JSONException
String. The value may be one of:
JSONObject.NULLBoolean.TRUE or Boolean.FALSEDouble, Long, Integer,
BigDecimal, or BigIntegerStringJSONObjectJSONArrays - A source string.JSONExceptionpublic static java.lang.Object buildJSONValue(java.lang.String s,
StructureCollector<?,?,?,?> collector)
throws JSONException
String. The value may be one of:
Boolean.TRUE or Boolean.FALSEDouble, Long, Integer,
BigDecimal, or BigIntegerStrings - A source string.collector - A collector object for creating structuresJSONExceptionpublic static java.lang.Object buildJSONValue(JSONStreamReader reader) throws JSONException
JSONStreamReader. The value may be one
of:
JSONObject.NULLBoolean.TRUE or Boolean.FALSEDouble, Long, Integer,
BigDecimal, or BigIntegerStringJSONObjectJSONArrayThe reader must be at the beginning of the document.
reader - A source stream reader.JSONExceptionpublic static java.lang.Object buildJSONValue(JSONStreamReader reader, StructureCollector<?,?,?,?> collector) throws JSONException
JSONStreamReader. The value may be one
of:
Boolean.TRUE or Boolean.FALSEDouble, Long, Integer,
BigDecimal, or BigIntegerStringThe reader must be at the beginning of the document.
reader - A source stream reader.collector - A collector object for creating structuresJSONExceptionpublic static JSONObject buildJSONObject(java.io.Reader reader) throws JSONException
JSONObject from a Reader.reader - A reader.JSONExceptionpublic static <OR> OR buildJSONObject(java.io.Reader reader,
StructureCollector<?,?,OR,?> collector)
throws JSONException
JSONObject from a Reader.OR - The resulting JSON object typereader - A reader.collector - A collector object for creating structuresJSONExceptionpublic static JSONObject buildJSONObject(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws JSONException
JSONObject from a InputStream and a supplied
Charset.inputStream - the input stream containing the JSON datacharset - the character set with which to interpret the
input streamJSONExceptionpublic static <OR> OR buildJSONObject(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,OR,?> collector)
throws JSONException
JSONObject from a InputStream and a supplied
Charset.OR - The resulting JSON object typeinputStream - the input stream containing the JSON datacharset - the character set with which to interpret the
input streamcollector - A collector object for creating structuresJSONExceptionpublic static JSONObject buildJSONObject(java.lang.String s) throws JSONException
JSONObject from a String.s - A source string.JSONExceptionpublic static <OR> OR buildJSONObject(java.lang.String s,
StructureCollector<?,?,OR,?> collector)
throws JSONException
JSONObject from a String.OR - The resulting JSON object types - A source string.collector - A collector object for creating structuresJSONExceptionpublic static JSONObject buildJSONObject(JSONStreamReader reader) throws JSONException
JSONObject from a JSONStreamReader. The reader must be
at the beginning of the document.reader - A source stream reader.JSONExceptionpublic static <OR> OR buildJSONObject(JSONStreamReader reader, StructureCollector<?,?,OR,?> collector) throws JSONException
JSONObject from a JSONStreamReader. The reader must be
at the beginning of the document.OR - The resulting JSON object typereader - A source stream reader.collector - A collector object for creating structuresJSONExceptionpublic static <AR> AR buildJSONArray(java.io.Reader reader,
StructureCollector<?,?,?,AR> collector)
throws JSONException
JSONArray from a Reader.AR - The resulting JSON array typereader - A reader.collector - A collector object for creating structuresJSONExceptionpublic static JSONArray buildJSONArray(java.io.Reader reader) throws JSONException
JSONArray from a Reader.reader - A reader.JSONExceptionpublic static JSONArray buildJSONArray(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws JSONException
JSONArray from a InputStream and a supplied
Charset.inputStream - the input stream containing the JSON datacharset - the character set with which to interpret the
input streamJSONExceptionpublic static <AR> AR buildJSONArray(java.io.InputStream inputStream,
java.nio.charset.Charset charset,
StructureCollector<?,?,?,AR> collector)
throws JSONException
JSONArray from a InputStream and a supplied
Charset.AR - The resulting JSON array typeinputStream - the input stream containing the JSON datacharset - the character set with which to interpret the
input streamcollector - A collector object for creating structuresJSONExceptionpublic static JSONArray buildJSONArray(java.lang.String s) throws JSONException
JSONArray from a String.s - A source string.JSONExceptionpublic static <AR> AR buildJSONArray(java.lang.String s,
StructureCollector<?,?,?,AR> collector)
throws JSONException
JSONArray from a String.AR - The resulting JSON array types - A source string.collector - A collector object for creating structuresJSONExceptionpublic static JSONArray buildJSONArray(JSONStreamReader reader) throws JSONException
JSONArray from a JSONStreamReader. The reader must be
at the beginning of the document.reader - A source stream.JSONExceptionpublic static <AR> AR buildJSONArray(JSONStreamReader reader, StructureCollector<?,?,?,AR> collector) throws JSONException
JSONArray from a JSONStreamReader. The reader must be
at the beginning of the document.AR - The resulting JSON array typereader - A source stream.collector - A collector object for creating structuresJSONExceptionpublic static JSONObject buildObjectSubTree(JSONStreamReader reader) throws JSONException
JSONStreamReader's ParseState was JSONStreamReader.ParseState.OBJECT,
return the entire subtree as a JSONObject value. This method
advances the parser onto the JSONStreamReader.ParseState.END_OBJECT state.
If the JSON stream is not parseable as an object, a JSONException
will be thrown.
reader - A source stream reader.JSONObject representing the subtree starting at the current
OBJECT stateJSONExceptionpublic static <OR> OR buildObjectSubTree(JSONStreamReader reader, StructureCollector<?,?,OR,?> collector) throws JSONException
JSONStreamReader's ParseState was JSONStreamReader.ParseState.OBJECT,
return the entire subtree as an object type, as specified by the given
collector. This method advances the parser onto the
JSONStreamReader.ParseState.END_OBJECT state.
If the JSON stream is not parseable as an object, a JSONException
will be thrown.
OR - The resulting JSON object typereader - A source stream reader.collector - A collector object for creating structuresJSONExceptionpublic static JSONArray buildArraySubTree(JSONStreamReader reader) throws JSONException
JSONStreamReader's ParseState was JSONStreamReader.ParseState.ARRAY,
return the entire subtree as a JSONArray value. This method
advances the parser onto the JSONStreamReader.ParseState.END_ARRAY state.
If the JSON stream is not parseable as an array, a JSONException
will be thrown.
reader - A source stream reader.JSONArray representing the subtree starting at the current
ARRAY stateJSONExceptionpublic static <AR> AR buildArraySubTree(JSONStreamReader reader, StructureCollector<?,?,?,AR> collector) throws JSONException
JSONStreamReader's ParseState was JSONStreamReader.ParseState.ARRAY,
return the entire subtree as an array type, as specified by the given
collector. This method advances the parser onto the
JSONStreamReader.ParseState.END_ARRAY state.
If the JSON stream is not parseable as an array, a JSONException
will be thrown.
AR - The resulting JSON array typereader - A source stream reader.collector - A collector object for creating structuresJSONException