public class JsonReader extends Object implements Closeable
object
or
array
from an input source.
For example, an empty JSON array can be created as follows:
JsonReader jsonReader = new JsonReader(new StringReader("[]"));
JsonArray array = jsonReader.readArray();
jsonReader.close();
It uses JsonParser
internally for parsing. The
parser is created using one of the Json
's createParser
methods.Constructor and Description |
---|
JsonReader(InputStream in)
Creates a JSON reader from a byte stream.
|
JsonReader(InputStream in,
Charset charset)
Creates a JSON reader from a byte stream.
|
JsonReader(InputStream in,
Charset charset,
JsonConfiguration config)
Creates a JSON reader from a byte stream.
|
JsonReader(Reader reader)
Creates a JSON reader from a character stream
|
JsonReader(Reader reader,
JsonConfiguration config)
Creates a JSON reader from a character stream
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this reader and frees any resources associated with the
reader.
|
JsonStructure |
read()
Returns a JSON array or object that is represented in
the input source.
|
JsonArray |
readArray()
Returns a JSON array that is represented in
the input source.
|
JsonObject |
readObject()
Returns a JSON object that is represented in
the input source.
|
public JsonReader(Reader reader)
reader
- a reader from which JSON is to be readpublic JsonReader(Reader reader, JsonConfiguration config)
reader
- a character stream from which JSON is to be readconfig
- configuration of the readerIllegalArgumentException
- if a feature in the configuration
is not knownpublic JsonReader(InputStream in)
in
- a byte stream from which JSON is to be readpublic JsonReader(InputStream in, Charset charset)
in
- a byte stream from which JSON is to be readcharset
- a charsetpublic JsonReader(InputStream in, Charset charset, JsonConfiguration config)
in
- a byte stream from which JSON is to be readcharset
- a charsetconfig
- configuration of the readerIllegalArgumentException
- if a feature in the configuration
is not knownpublic JsonStructure read()
JsonException
- if a JSON object or array cannot
be created due to i/o error (IOException would be
cause of JsonException)JsonParsingException
- if a JSON object or array cannot
be created due to incorrect representationIllegalStateException
- if this method, readObject, readArray or
close method is already calledpublic JsonObject readObject()
JsonException
- if a JSON object cannot
be created due to i/o error (IOException would be
cause of JsonException)JsonParsingException
- if a JSON object cannot
be created due to incorrect representationIllegalStateException
- if this method, readObject, readArray or
close method is already calledpublic JsonArray readArray()
JsonException
- if a JSON array cannot
be created due to i/o error (IOException would be
cause of JsonException)JsonParsingException
- if a JSON array cannot
be created due to incorrect representationIllegalStateException
- if this method, readObject, readArray or
close method is already calledpublic void close()
close
in interface Closeable
close
in interface AutoCloseable
JsonException
- if an i/o error occurs (IOException would be
cause of JsonException)Copyright © 2013. All Rights Reserved.