public class JsonParser extends Object
Note that the event and member values are only valid while the parser is not searching for the next event.
Threading Design : [x] Single Threaded [ ] Thread-safe [ ] Immutable [ ] Isolated
| Modifier and Type | Class and Description |
|---|---|
static class |
JsonParser.Escape |
static class |
JsonParser.Location |
| Modifier and Type | Field and Description |
|---|---|
static int |
EVT_ARRAY_BEGIN
Returned from next() when the beginning of a declared array is read.
|
static int |
EVT_ARRAY_ENDED
Returned from next() when the end of a declared array is read.
|
static int |
EVT_INPUT_ENDED
Returned from next() when the end of the input source is reached.
|
static int |
EVT_OBJECT_BEGIN
Returned from next() when the beginning of an object is read.
|
static int |
EVT_OBJECT_ENDED
Returned from next() when the end of an object is read.
|
static int |
EVT_OBJECT_MEMBER
Returned from next() when a simple object member (Name:Value pair or
array element) is read.
|
static int |
OPT_ALL
All options on.
|
static int |
OPT_CONFIG
Recommended for config parsing mode - OPT_UNQUOTED_KEYWORDS,
OPT_EOL_IS_COMMA, OPT_MULTILINE_COMMENTS, OPT_SINGLE_QUOTE_STRINGS,
OPT_INTERN_KEYWORDS, OPT_INTERN_VALUES.
|
static int |
OPT_EOL_IS_COMMA
Option to allow an end-of-line to be treated as a comma.
|
static int |
OPT_INTERN_KEYWORDS
Option to cause keywords to be interned (String.intern()) - this is not a
JSON compliance option.
|
static int |
OPT_INTERN_VALUES
Option to cause keywords to be interned (String.intern()) - this is not a
JSON compliance option.
|
static int |
OPT_MESSAGING
Recommended options for messaging parsing mode - OPT_UNQUOTED_KEYWORDS,
OPT_INTERN_KEYWORDS.
|
static int |
OPT_MULTILINE_COMMENTS
Option to allow multiline comments using /* and */.
|
static int |
OPT_MULTILINE_STRINGS
Option to allow mutiline strings - this permits strings to be broken over
multiple lines in an unambigous manner.
|
static int |
OPT_PRELOAD_INPUT
Option to preload file input data when the input source is set - this is
not a JSON compliance option.
|
static int |
OPT_SINGLE_QUOTE_STRINGS
Option to allow single-quotes to be used for strings.
|
static int |
OPT_STRICT
All options off.
|
static int |
OPT_UNQUOTED_KEYWORDS
Option to allow keywords to be unquoted.
|
| Constructor and Description |
|---|
JsonParser(int opt)
Construct a JSON parser from a character input source.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Reset this parser, and clear any internal caches or pools used to improve
performance.
|
static Object |
createTypedValue(String val)
Create a typed member value applying JSON typing rules.
|
int |
getEventCode()
Get the code for the current event.
|
int |
getEventColumn()
Get the input source column number for the current event.
|
int |
getEventLine()
Get the input source line number for the current event.
|
JsonParser.Location |
getEventLocation()
Get the input source location for the current event.
|
String |
getEventName()
Get the name for the current event.
|
static String |
getEventName(int cod)
Get a text name for the event code.
|
JsonParser.Location |
getInputLocation()
Get the current location in the input source.
|
String |
getInputName()
Get the name assigned to the input source at construction.
|
boolean |
getMemberArray()
Get the current object member array flag.
|
String |
getMemberName()
Get the current object member name.
|
String |
getMemberValue()
Get the current object member value (valid only if the current event is
EVT_OBJECT_MEMBER).
|
String |
getObjectName()
Get the name of the current object.
|
static Object |
getTypedMemberValue(String val)
Get the current object member value applying JSON typing rules (valid
only if the current event is EVT_OBJECT_MEMBER).
|
static boolean |
isQuoted(String val)
Test if the member value is enclosed in text-value-indicating quotes.
|
int |
next()
Parse next event from input source.
|
void |
reset()
Reset this parser to be ready for more input after completing the parsing
of some input.
|
JsonParser |
setInput(File inpfil,
String inpenc,
int bufsiz)
Construct a JSON parser from a file input source.
|
JsonParser |
setInput(String inpnam,
InputStream inpsrc,
String inpenc,
boolean inpcls)
Construct a JSON parser from a byte input source.
|
JsonParser |
setInput(String inpnam,
Reader inpsrc,
boolean inpcls)
Construct a JSON parser from a character input source.
|
JsonParser |
setInput(String inpfil,
String inpenc,
int bufsiz)
Construct a JSON parser from a file input source.
|
void |
skipArray()
Skip the array that the parser is currently positioned at.
|
void |
skipObject()
Skip the object that the parser is currently positioned at.
|
static String |
stripQuotes(String val)
Strip the text-value-indicating quotes from the supplied member value, if
any.
|
public static final int EVT_OBJECT_BEGIN
public static final int EVT_OBJECT_ENDED
public static final int EVT_ARRAY_BEGIN
public static final int EVT_ARRAY_ENDED
public static final int EVT_INPUT_ENDED
public static final int EVT_OBJECT_MEMBER
public static final int OPT_UNQUOTED_KEYWORDS
public static final int OPT_EOL_IS_COMMA
public static final int OPT_MULTILINE_COMMENTS
public static final int OPT_MULTILINE_STRINGS
public static final int OPT_SINGLE_QUOTE_STRINGS
public static final int OPT_PRELOAD_INPUT
public static final int OPT_INTERN_KEYWORDS
public static final int OPT_INTERN_VALUES
public static final int OPT_STRICT
public static final int OPT_MESSAGING
public static final int OPT_CONFIG
public static final int OPT_ALL
public JsonParser(int opt)
opt - Parsing option flags, combined from OPT_xxx values.public void close()
public void reset()
public String getInputName()
public JsonParser.Location getInputLocation()
public String getObjectName()
public int getEventCode()
public String getEventName()
public int getEventLine()
public int getEventColumn()
public JsonParser.Location getEventLocation()
public String getMemberName()
public String getMemberValue()
NOTE
All values are returned with EMCA-262 unescaping already applied. However
if the value was specified in quotes it is return enclosed in quotes in
order to reflect the explicit indication of a text value. This means that
the string may contain ambiguous quotes when observed at face value,
which situation is easily resolve using the static methods
isQuoted() and stripQuotes. Alternatively, the
methods getTypedMemberValue() or
createTypeValue() may be used to get a Java typed object,
which may be identified using instanceof.
public boolean getMemberArray()
public static Object getTypedMemberValue(String val)
Actual return types are as follows:
NumberFormatException - If an unquoted value which is no null, true
or false is not a valid decimal number.public JsonParser setInput(String inpnam, Reader inpsrc, boolean inpcls)
inpnam - A text description of the source, used only for location
text.inpsrc - Input source.inpcls - Whether to close the input source at end-of-input.public JsonParser setInput(String inpnam, InputStream inpsrc, String inpenc, boolean inpcls)
inpnam - A text description of the source, used only for location
text.inpsrc - Input source.inpenc - Character encoding used by the input source.inpcls - Whether to close the input source at end-of-input.public JsonParser setInput(String inpfil, String inpenc, int bufsiz)
inpfil - Input source.inpenc - Character encoding used by the input source.bufsiz - Size of input buffer for reading from the file.public JsonParser setInput(File inpfil, String inpenc, int bufsiz)
inpfil - Input source.inpenc - Character encoding used by the input source.bufsiz - Size of input buffer for reading from the file.public int next()
public void skipObject()
public void skipArray()
public static Object createTypedValue(String val)
Actual return types are as follows:
NumberFormatException - If an unquoted value which is no null, true
or false is not a valid decimal number.public static String getEventName(int cod)
public static String stripQuotes(String val)
public static boolean isQuoted(String val)
Copyright © 2014 FreeLibrary. All Rights Reserved.