/** * Get the next n characters. * * @param n The number of characters to take. * @return A string of n characters. * @throws JSONException * Substring bounds error if there are not * n characters remaining in the source string. */ public String next(int n) throws JSONException { int i = this.myIndex; int j = i + n; if (j >= this.mySource.length()) { throw syntaxError("Substring bounds error"); } this.myIndex += n; return this.mySource.substring(i, j); }
/** * Consume the next character, and check that it matches a specified * character. * @param c The character to match. * @return The character. * @throws JSONException if the character does not match. */ public char next(char c) throws JSONException { char n = next(); if (n != c) { throw syntaxError("Expected '" + c + "' and instead saw '" + n + "'."); } return n; }
/** * Strictly validate the JSON text * @param text The text to check. * @throws JSONException If the text is not valid. */ public static void validate(final String text) throws JSONException { JSONTokener x = new JSONTokener(text); validate(x); // make sure nothing more is present after last array or object char c = x.nextClean(); if ( c != 0 ) { throw x.syntaxError("Unexpected '" + c + "' at end of file."); } }
case '\n': case '\r': throw syntaxError("Unterminated string"); case '\\': c = next();
throw syntaxError("Missing value.");
throw x.syntaxError("A JSONObject text must begin with '{'"); switch (c) { case 0: throw x.syntaxError("A JSONObject text must end with '}'"); case '}': return; throw x.syntaxError("Expected a ':' after a key"); return; default: throw x.syntaxError("Expected a ',' or '}'");
throw x.syntaxError("Detected unclosed array."); throw x.syntaxError("Trailing separator ',' in array."); default: throw x.syntaxError("Expected a ',' or ']'"); c = x.nextClean(); switch (c) { case 0 : throw x.syntaxError("A JSONObject text must end with '}'"); case '}': return; default : x.back(); throw x.syntaxError("Expected a ':' after a key"); throw x.syntaxError("JSONObject contains key '" + key + "' multiple times."); throw x.syntaxError("Trailing separator ',' in object."); default: throw x.syntaxError("Expected a ',' or '}'"); throw x.syntaxError("A JSON text must begin with '{' (for an object) or '[' (for an array).");
/** * Produce a JSONArray of strings from a row of comma delimited values. * @param x A JSONTokener of the source text. * @return A JSONArray of strings. * @throws JSONException */ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException { JSONArray ja = new JSONArray(); for (;;) { String value = getValue(x); if (value == null) { return null; } ja.put(value); for (;;) { char c = x.next(); if (c == ',') { break; } if (c != ' ') { if (c == '\n' || c == '\r' || c == 0) { return ja; } throw x.syntaxError("Bad character '" + c + "' (" + (int)c + ")."); } } } }
this(); if (x.nextClean() != '[') { throw x.syntaxError("A JSONArray text must start with '['"); return; default: throw x.syntaxError("Expected a ',' or ']'");
c = next(); if (c == 0) { throw syntaxError("Unclosed comment.");
v = Boolean.TRUE; } else { throw x.syntaxError("Missing '=' in cookie parameter.");