public class JsonParser
extends java.lang.Object
A non-blocking, event-based JSON parser.
The parser gets input data from a feeder that can be accessed through
getFeeder(). See JsonFeeder for more details.
| Constructor and Description |
|---|
JsonParser()
Constructs a JSON parser that uses the UTF-8 charset to decode input data
|
JsonParser(java.nio.charset.Charset charset)
Constructs a JSON parser
|
JsonParser(JsonFeeder feeder)
Constructs the JSON parser
|
| Modifier and Type | Method and Description |
|---|---|
double |
getCurrentDouble()
If the event returned by
nextEvent() was
JsonEvent.VALUE_DOUBLE this method will return the parsed double |
int |
getCurrentInt()
If the event returned by
nextEvent() was
JsonEvent.VALUE_INT this method will return the parsed integer |
long |
getCurrentLong()
If the event returned by
nextEvent() was
JsonEvent.VALUE_INT this method will return the parsed long integer |
java.lang.String |
getCurrentString()
If the event returned by
nextEvent() was
JsonEvent.VALUE_STRING this method will return the parsed string |
JsonFeeder |
getFeeder()
Get the feeder that can be used to provide more input to the parser
|
int |
getMaxDepth() |
long |
getParsedCharacterCount()
Get the number of characters processed by the JSON parser so far.
|
int |
nextEvent()
Call this method to proceed parsing the JSON text and to get the next
event.
|
void |
setMaxDepth(int depth)
Set the maximum number of modes on the stack (basically the maximum number
of nested objects/arrays in the JSON text to parse)
|
public JsonParser()
public JsonParser(java.nio.charset.Charset charset)
charset - the charset that should be used to decode the
parser's input datapublic JsonParser(JsonFeeder feeder)
feeder - the feeder that will provide the parser with input datapublic void setMaxDepth(int depth)
depth - the maximum number of modespublic int getMaxDepth()
public int nextEvent()
JsonEvent.NEED_MORE_INPUT if it needs
more input data from the parser's feeder.JsonEvent.NEED_MORE_INPUT if more
input is neededpublic JsonFeeder getFeeder()
public java.lang.String getCurrentString()
nextEvent() was
JsonEvent.VALUE_STRING this method will return the parsed stringpublic int getCurrentInt()
nextEvent() was
JsonEvent.VALUE_INT this method will return the parsed integerpublic long getCurrentLong()
nextEvent() was
JsonEvent.VALUE_INT this method will return the parsed long integerpublic double getCurrentDouble()
nextEvent() was
JsonEvent.VALUE_DOUBLE this method will return the parsed doublepublic long getParsedCharacterCount()
Get the number of characters processed by the JSON parser so far.
Use this method to get the location of an event returned by
nextEvent(). Note that the character count is always greater than
the actual position of the event in the parsed JSON text. For example, if
nextEvent() returns JsonEvent.START_OBJECT and the
character count is n, the location of the {
character is n-1. If nextEvent() returns
JsonEvent.FIELD_NAME and the parsed field name is
"id", the location is n-4 because the field
name is 4 characters long (including the quotes) and the parser has
already processed all characters of it.