public class JSONTokener extends java.lang.Object
It is used by the JSONObject and JSONArray constructors to parse JSON source strings.
Constructor and Description |
---|
JSONTokener(java.io.Reader reader)
Construct a JSONTokener from a string.
|
JSONTokener(java.lang.String s)
Construct a JSONTokener from a string.
|
Modifier and Type | Method and Description |
---|---|
void |
back()
Back up one character.
|
static int |
dehexchar(char c)
Get the hex value of a character (base16).
|
boolean |
more()
Determine if the source string still contains characters that next()
can consume.
|
char |
next()
Get the next character in the source string.
|
char |
next(char c)
Consume the next character, and check that it matches a specified
character.
|
java.lang.String |
next(int n)
Get the next n characters.
|
char |
nextClean()
Get the next char in the string, skipping whitespace
and comments (slashslash, slashstar, and hash).
|
java.lang.String |
nextString(char quote)
Return the characters up to the next close quote character.
|
java.lang.String |
nextTo(char d)
Get the text up but not including the specified character or the
end of line, whichever comes first.
|
java.lang.String |
nextTo(java.lang.String delimiters)
Get the text up but not including one of the specified delimiter
characters or the end of line, whichever comes first.
|
java.lang.Object |
nextValue()
Get the next value.
|
void |
setOrdered(boolean ordered)
Sets a flag which makes JSONObjects created by this tokener ordered.
|
char |
skipTo(char to)
Skip characters until the next character is the requested character.
|
JSONException |
syntaxError(java.lang.String message)
Make a JSONException to signal a syntax error.
|
java.lang.String |
toString()
Make a printable string of this JSONTokener.
|
public JSONTokener(java.io.Reader reader)
reader
- a reader.public JSONTokener(java.lang.String s)
s
- a source stringpublic void back() throws JSONException
This provides a sort of lookahead capability, so that you can test for a digit or letter before attempting to parse the next number or identifier.
JSONException
- if something goes wrongpublic static int dehexchar(char c)
c
- a character between '0' and '9' or between 'A' and 'F' or
between 'a' and 'f'public boolean more() throws JSONException
JSONException
- if something goes wrongpublic char next() throws JSONException
JSONException
- if something goes wrongpublic char next(char c) throws JSONException
c
- the character to matchJSONException
- if the character does not matchpublic java.lang.String next(int n) throws JSONException
n
- the number of characters to takeJSONException
- substring bounds error if there are not n characters remaining in the source stringpublic char nextClean() throws JSONException
JSONException
- if something goes wrongpublic java.lang.String nextString(char quote) throws JSONException
Backslash processing is done. The formal JSON format does not allow strings in single quotes, but an implementation is allowed to accept them.
quote
- The quoting character, either
"
(double quote) or
'
(single quote)JSONException
- in case of an unterminated stringpublic java.lang.String nextTo(char d) throws JSONException
d
- a delimiter characterJSONException
- if something goes wrongpublic java.lang.String nextTo(java.lang.String delimiters) throws JSONException
delimiters
- a set of delimiter charactersJSONException
- if something goes wrongpublic java.lang.Object nextValue() throws JSONException
JSONException
- if something goes wrongpublic void setOrdered(boolean ordered)
ordered
- true if JSONObjects created by this should be orderedpublic char skipTo(char to) throws JSONException
to
- a character to skip toJSONException
- if something goes wrongpublic JSONException syntaxError(java.lang.String message)
message
- the error messagepublic java.lang.String toString()
toString
in class java.lang.Object