| java.lang.Object | |
| ↳ | org.json.JSONTokener | 
       Parses a JSON (
       
        RFC 4627
       
       )
 encoded string into the corresponding object. Most clients of
 this class will use only need the
       
        
         constructor
        
       
       and
       
        
         nextValue()
        
       
       method. Example usage:
       
        String json = "{"
         + "  \"query\": \"Pizza\", "
         + "  \"locations\": [ 94043, 90210 ] "
         + "}";
 JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
 String query = object.getString("query");
 JSONArray locations = object.getJSONArray("locations");
       
      
      
       For best interoperability and performance use JSON that complies with
 RFC 4627, such as that generated by
       
        
         JSONStringer
        
       
       . For legacy reasons
 this parser is lenient, so a successful parse does not indicate that the
 input string was valid JSON. All of the following syntax errors will be
 ignored:
       
          //
         
         or
         
          #
         
         and ending
       with a newline character.
        
          /*
         
         and ending with
         
          *
         
         
          /
         
         . Such comments may not be nested.
        
          'single quoted'
         
         .
        
          0x
         
         or
         
          0X
         
         .
        
          0
         
         .
        
          ;
         
         .
        
          =
         
         or
         
          =>
         
         .
        
          ;
         
         .
        Each tokener may be used to parse a single JSON string. Instances of this class are not thread safe. Although this class is nonfinal, it was not designed for inheritance and should not be subclassed. In particular, self-use by overrideable methods is not specified. See Effective Java Item 17, "Design and Document or inheritance or else prohibit it" for further information.
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 
          | 
        
          | 
       ||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 
          | 
        
          
          Unreads the most recent character of input.
          
         | 
       ||||||||||
| 
          | 
        
          
          Returns the integer [0..15] value for the given hex character, or -1
 for non-hex input.
          
         | 
       ||||||||||
| 
          | 
        
          
          Returns true until the input has been exhausted.
          
         | 
       ||||||||||
| 
          | 
        
          
          Returns the next
           
        
           length
          
          characters of the input.
          | 
       ||||||||||
| 
          | 
        
          
          Returns the next available character, or the null character '\0' if all
 input has been exhausted.
          
         | 
       ||||||||||
| 
          | 
        
          
          Returns the next available character if it equals
           
        
           c
          
          .
          | 
       ||||||||||
| 
          | 
        
          
          Returns the next character that is not whitespace and does not belong to
 a comment.
          
         | 
       ||||||||||
| 
          | 
        
          
          Returns the string up to but not including
           
        
           quote
          
          , unescaping any
 character escape sequences encountered along the way.
          | 
       ||||||||||
| 
          | 
        
          
          Equivalent to
           
        
           nextTo(String.valueOf(excluded))
          
          .
          | 
       ||||||||||
| 
          | 
        
          
          Returns the
           
        
           
            trimmed
           
          
          string holding the characters up
 to but not including the first of:
          
 The returned string shares its backing character array with this tokener's input string.  | 
       ||||||||||
| 
          | 
        
          
          Returns the next value from the input.
          
         | 
       ||||||||||
| 
          | 
        
          
          Advances past all input up to and including the next occurrence of
           
        
           thru
          
          .
          | 
       ||||||||||
| 
          | 
        
          
          Advances past all input up to but not including the next occurrence of
           
        
           to
          
          .
          | 
       ||||||||||
| 
          | 
        
          
          Returns an exception containing the given message plus the current
 position and the entire input string.
          
         | 
       ||||||||||
| 
          | 
        
          
          Returns the current position and the entire input string.
          
         | 
       ||||||||||
| 
         
          [Expand]
         
          
          Inherited Methods
          
         | 
       |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
         
           
         
         From class
         
          java.lang.Object
         
          | 
       |||||||||||
| in | 
           JSON encoded string. Null is not permitted and will yield a
     tokener that throws
           
            NullPointerExceptions
           
           when methods are
     called.
           | 
         
|---|
Unreads the most recent character of input. If no input characters have been read, the input is unchanged.
Returns the integer [0..15] value for the given hex character, or -1 for non-hex input.
| hex | a character in the ranges [0-9], [A-F] or [a-f]. Any other character will yield a -1 result. | 
|---|
         Returns the next
         
          length
         
         characters of the input.
        
         The returned string shares its backing character array with this
 tokener's input string. If a reference to the returned string may be held
 indefinitely, you should use
         
          new String(result)
         
         to copy it first
 to avoid memory leaks.
        
| JSONException | if the remaining input is not long enough to satisfy this request. | 
|---|
Returns the next available character, or the null character '\0' if all input has been exhausted. The return value of this method is ambiguous for JSON strings that contain the character '\0'.
         Returns the next available character if it equals
         
          c
         
         . Otherwise an
 exception is thrown.
        
| JSONException | 
|---|
Returns the next character that is not whitespace and does not belong to a comment. If the input is exhausted before such a character can be found, the null character '\0' is returned. The return value of this method is ambiguous for JSON strings that contain the character '\0'.
| JSONException | 
|---|
         Returns the string up to but not including
         
          quote
         
         , unescaping any
 character escape sequences encountered along the way. The opening quote
 should have already been read. This consumes the closing quote, but does
 not include it in the returned string.
        
| quote | either ' or ". | 
|---|
| NumberFormatException | if any unicode escape sequences are malformed. | 
|---|---|
| JSONException | 
         Equivalent to
         
          nextTo(String.valueOf(excluded))
         
         .
        
         Returns the
         
          
           trimmed
          
         
         string holding the characters up
 to but not including the first of:
         
            excluded
           
          
         The returned string shares its backing character array with this
 tokener's input string. If a reference to the returned string may be held
 indefinitely, you should use
         
          new String(result)
         
         to copy it first
 to avoid memory leaks.
        
Returns the next value from the input.
           
            JSONObject
           
          
          ,
          
           
            JSONArray
           
          
          , String, Boolean,
     Integer, Long, Double or
          
           
            NULL
           
          
          .
         | JSONException | if the input is malformed. | 
|---|
         Advances past all input up to and including the next occurrence of
         
          thru
         
         . If the remaining input doesn't contain
         
          thru
         
         , the
 input is exhausted.
        
         Advances past all input up to but not including the next occurrence of
         
          to
         
         . If the remaining input doesn't contain
         
          to
         
         , the input
 is unchanged.
        
Returns an exception containing the given message plus the current position and the entire input string.
Returns the current position and the entire input string.