Node Director
Public Member Functions | Static Public Member Functions | List of all members
org.json.JSONTokener Class Reference

A JSONTokener takes a source string and extracts characters and tokens from it. More...

Inheritance diagram for org.json.JSONTokener:
org.json.HTTPTokener org.json.XMLTokener

Public Member Functions

 JSONTokener (String s)
 Construct a JSONTokener from a string.
void back ()
 Back up one character.
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) throws ParseException
 Consume the next character, and check that it matches a specified character.
String next (int n) throws ParseException
 Get the next n characters.
char nextClean () throws java.text.ParseException
 Get the next char in the string, skipping whitespace and comments (slashslash, slashstar, and hash).
String nextString (char quote) throws ParseException
 Return the characters up to the next close quote character.
String nextTo (char d)
 Get the text up but not including the specified character or the end of line, whichever comes first.
String nextTo (String delimiters)
 Get the text up but not including one of the specified delimeter characters or the end of line, whichever comes first.
Date nextDate () throws ParseException
Object nextValue () throws ParseException
 Get the next value.
char skipTo (char to)
 Skip characters until the next character is the requested character.
void skipPast (String to)
 Skip characters until past the requested string.
ParseException syntaxError (String message)
 Make a ParseException to signal a syntax error.
String toString ()
 Make a printable string of this JSONTokener.

Static Public Member Functions

static int dehexchar (char c)
 Get the hex value of a character (base16).
static String unescape (String s)
 Convert %hh sequences to single characters, and convert plus to space.

Detailed Description

A JSONTokener takes a source string and extracts characters and tokens from it.

It is used by the JSONObject and JSONArray constructors to parse JSON source strings.

Author
JSON.org
Version
1

Constructor & Destructor Documentation

org.json.JSONTokener.JSONTokener ( String  s)

Construct a JSONTokener from a string.

Parameters
sA source string.

Member Function Documentation

void org.json.JSONTokener.back ( )

Back up one character.

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.

Referenced by org.json.JSONTokener.nextClean(), org.json.XMLTokener.nextContent(), org.json.XMLTokener.nextMeta(), org.json.JSONTokener.nextTo(), org.json.XMLTokener.nextToken(), org.json.JSONTokener.nextValue(), and org.json.JSONTokener.skipTo().

static int org.json.JSONTokener.dehexchar ( char  c)
static

Get the hex value of a character (base16).

Parameters
cA character between '0' and '9' or between 'A' and 'F' or between 'a' and 'f'.
Returns
An int between 0 and 15, or -1 if c was not a hex digit.

Referenced by org.json.JSONTokener.unescape().

boolean org.json.JSONTokener.more ( )

Determine if the source string still contains characters that next() can consume.

Returns
true if not yet at the end of the source.

Referenced by org.json.JSONTokener.next(), org.json.CookieList.toJSONObject(), org.json.HTTP.toJSONObject(), org.json.Cookie.toJSONObject(), and org.json.XML.toJSONObject().

char org.json.JSONTokener.next ( )
char org.json.JSONTokener.next ( char  c) throws ParseException

Consume the next character, and check that it matches a specified character.

Parameters
cThe character to match.
Returns
The character.
Exceptions
ParseExceptionif the character does not match.

References org.json.JSONTokener.next(), and org.json.JSONTokener.syntaxError().

String org.json.JSONTokener.next ( int  n) throws ParseException

Get the next n characters.

Parameters
nThe number of characters to take.
Returns
A string of n characters.
Exceptions
ParseExceptionSubstring bounds error if there are not n characters remaining in the source string.

References org.json.JSONTokener.syntaxError().

char org.json.JSONTokener.nextClean ( ) throws java.text.ParseException

Get the next char in the string, skipping whitespace and comments (slashslash, slashstar, and hash).

Exceptions
ParseException
Returns
A character, or 0 if there are no more characters.

References org.json.JSONTokener.back(), org.json.JSONTokener.next(), and org.json.JSONTokener.syntaxError().

Referenced by org.json.JSONTokener.nextDate(), and org.json.JSONTokener.nextValue().

Date org.json.JSONTokener.nextDate ( ) throws ParseException
String org.json.JSONTokener.nextString ( char  quote) throws ParseException

Return the characters up to the next close quote character.

Backslash processing is done. The formal JSON format does not allow strings in single quotes, but an implementation is allowed to accept them.

Parameters
quoteThe quoting character, either " (double quote) or ' (single quote).
Returns
A String.
Exceptions
ParseExceptionUnterminated string.

References org.json.JSONTokener.next(), and org.json.JSONTokener.syntaxError().

Referenced by org.json.JSONTokener.nextValue().

String org.json.JSONTokener.nextTo ( char  d)

Get the text up but not including the specified character or the end of line, whichever comes first.

Parameters
dA delimiter character.
Returns
A string.

References org.json.JSONTokener.back(), and org.json.JSONTokener.next().

Referenced by org.json.JSONTokener.nextDate(), org.json.CookieList.toJSONObject(), org.json.HTTP.toJSONObject(), and org.json.Cookie.toJSONObject().

String org.json.JSONTokener.nextTo ( String  delimiters)

Get the text up but not including one of the specified delimeter characters or the end of line, whichever comes first.

Parameters
delimitersA set of delimiter characters.
Returns
A string, trimmed.

References org.json.JSONTokener.back(), and org.json.JSONTokener.next().

Object org.json.JSONTokener.nextValue ( ) throws ParseException

Get the next value.

The value can be a Boolean, Double, Integer, JSONArray, JSONObject, or String, or the JSONObject.NULL object.

Exceptions
ParseExceptionThe source does not conform to JSON syntax.
Returns
An object.

References org.json.JSONTokener.back(), org.json.JSONTokener.next(), org.json.JSONTokener.nextClean(), org.json.JSONTokener.nextDate(), org.json.JSONTokener.nextString(), org.json.JSONObject.NULL, and org.json.JSONTokener.syntaxError().

void org.json.JSONTokener.skipPast ( String  to)

Skip characters until past the requested string.

If it is not found, we are left at the end of the source.

Parameters
toA string to skip past.

Referenced by org.json.XML.toJSONObject().

char org.json.JSONTokener.skipTo ( char  to)

Skip characters until the next character is the requested character.

If the requested character is not found, no characters are skipped.

Parameters
toA character to skip to.
Returns
The requested character, or zero if the requested character is not found.

References org.json.JSONTokener.back(), and org.json.JSONTokener.next().

Referenced by org.json.Test.main().

ParseException org.json.JSONTokener.syntaxError ( String  message)
String org.json.JSONTokener.toString ( )

Make a printable string of this JSONTokener.

Returns
" at character [this.myIndex] of [this.mySource]"

Referenced by org.json.JSONTokener.syntaxError().

static String org.json.JSONTokener.unescape ( String  s)
static

Convert %hh sequences to single characters, and convert plus to space.

Parameters
sA string that may contain + (plus) and %hh sequences.
Returns
The unescaped string.

References org.json.JSONTokener.dehexchar().

Referenced by org.json.CookieList.toJSONObject(), and org.json.Cookie.toJSONObject().


The documentation for this class was generated from the following file: