java.lang.Object
org.springframework.boot.configurationprocessor.json.JSONTokener

public class JSONTokener extends Object
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 the following syntax errors will be ignored:

  • End of line comments starting with // or # and ending with a newline character.
  • C-style comments starting with /* and ending with */. Such comments may not be nested.
  • Strings that are unquoted or 'single quoted'.
  • Hexadecimal integers prefixed with 0x or 0X.
  • Octal integers prefixed with 0.
  • Array elements separated by ;.
  • Unnecessary array separators. These are interpreted as if null was the omitted value.
  • Key-value pairs separated by = or =>.
  • Key-value pairs separated by ;.

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.

  • Constructor Details

    • JSONTokener

      public JSONTokener(String in)
      Parameters:
      in - JSON encoded string. Null is not permitted and will yield a tokener that throws NullPointerExceptions when methods are called.
  • Method Details

    • nextValue

      public Object nextValue() throws JSONException
      Returns the next value from the input.
      Returns:
      a JSONObject, JSONArray, String, Boolean, Integer, Long, Double or JSONObject.NULL.
      Throws:
      JSONException - if the input is malformed.
    • nextString

      public String nextString(char quote) throws 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.
      Parameters:
      quote - either ' or ".
      Returns:
      the string up to but not including quote
      Throws:
      NumberFormatException - if any unicode escape sequences are malformed.
      JSONException - if processing of json failed
    • syntaxError

      public JSONException syntaxError(String message)
      Returns an exception containing the given message plus the current position and the entire input string.
      Parameters:
      message - the message
      Returns:
      an exception
    • toString

      public String toString()
      Returns the current position and the entire input string.
      Overrides:
      toString in class Object
      Returns:
      the current position and the entire input string.
    • more

      public boolean more()
    • next

      public char next()
    • next

      public char next(char c) throws JSONException
      Throws:
      JSONException
    • nextClean

      public char nextClean() throws JSONException
      Throws:
      JSONException
    • next

      public String next(int length) throws JSONException
      Throws:
      JSONException
    • nextTo

      public String nextTo(String excluded)
    • nextTo

      public String nextTo(char excluded)
    • skipPast

      public void skipPast(String thru)
    • skipTo

      public char skipTo(char to)
    • back

      public void back()
    • dehexchar

      public static int dehexchar(char hex)