/** * Construct a JSONArray from a source JSON text.<p> * * @param source a string that begins with * <code>[</code> <small>(left bracket)</small> * and ends with <code>]</code> <small>(right bracket)</small> * @throws JSONException if there is a syntax error */ public JSONArray(String source) throws JSONException { this(new JSONTokener(source)); }
char c = x.nextClean(); char q; if (c == '[') { q = ')'; } else { throw x.syntaxError("A JSONArray text must start with '['"); if (x.nextClean() == ']') { return; x.back(); for (;;) { if (x.nextClean() == ',') { x.back(); m_myArrayList.add(null); } else { x.back(); m_myArrayList.add(x.nextValue()); c = x.nextClean(); switch (c) { case ';': case ',': if (x.nextClean() == ']') { return; x.back(); break;
/** * Determine if the source string still contains characters that next() * can consume.<p> * * @return true if not yet at the end of the source * @throws JSONException if something goes wrong */ public boolean more() throws JSONException { char nextChar = next(); if (nextChar == 0) { return false; } back(); return true; }
/** * Consume the next character, and check that it matches a specified * character.<p> * * @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; }
/** * Get the next value. The value can be wrapped in quotes. The value can * be empty.<p> * * @param x A JSONTokener of the source text * @return The value string, or null if empty * @throws JSONException if the quoted string is badly formed */ private static String getValue(JSONTokener x) throws JSONException { char c; do { c = x.next(); } while ((c == ' ') || (c == '\t')); switch (c) { case 0: return null; case '"': case '\'': return x.nextString(c); case ',': x.back(); return ""; default: x.back(); return x.nextTo(','); } } }
char c = nextClean(); String s; case '"': case '\'': return nextString(c); case '{': back(); return new JSONObject(this, m_ordered); case '[': case '(': back(); return new JSONArray(this); default: while ((c >= ' ') && (",:]}/\\\"[{;=#".indexOf(c) < 0)) { sb.append(c); c = next(); back(); throw syntaxError("Missing value");
char c = next(); if (c == '/') { switch (next()) { case '/': do { c = next(); } while ((c != '\n') && (c != '\r') && (c != 0)); break; case '*': for (;;) { c = next(); if (c == 0) { throw syntaxError("Unclosed comment"); if (next() == '/') { break; back(); back(); return '/'; c = next(); } while ((c != '\n') && (c != '\r') && (c != 0)); } else if ((c == 0) || (c > ' ')) {
JSONTokener tok = new JSONTokener(fileContent); tok.setOrdered(true); JSONObject root = new JSONObject(tok, true); for (String templateContextName : root.keySet()) {
/** * Make a JSONException to signal a syntax error.<p> * * @param message the error message * @return a JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
throw syntaxError("Substring bounds error");
char c = nextClean(); String s; case '"': case '\'': return nextString(c); case '{': back(); return new JSONObject(this); case '[': case '(': back(); return new JSONArray(this); default: while ((c >= ' ') && (",:]}/\\\"[{;=#".indexOf(c) < 0)) { sb.append(c); c = next(); back(); throw syntaxError("Missing value");
/** * Get the next value. The value can be wrapped in quotes. The value can * be empty.<p> * * @param x A JSONTokener of the source text * @return The value string, or null if empty * @throws JSONException if the quoted string is badly formed */ private static String getValue(JSONTokener x) throws JSONException { char c; do { c = x.next(); } while (c == ' ' || c == '\t'); switch (c) { case 0: return null; case '"': case '\'': return x.nextString(c); case ',': x.back(); return ""; default: x.back(); return x.nextTo(','); } } }
/** * Consume the next character, and check that it matches a specified * character.<p> * * @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; }
char c = next(); if (c == '/') { switch (next()) { case '/': do { c = next(); } while ((c != '\n') && (c != '\r') && (c != 0)); break; case '*': for (;;) { c = next(); if (c == 0) { throw syntaxError("Unclosed comment"); if (next() == '/') { break; back(); back(); return '/'; c = next(); } while ((c != '\n') && (c != '\r') && (c != 0)); } else if ((c == 0) || (c > ' ')) {
/** * Make a JSONException to signal a syntax error.<p> * * @param message the error message * @return a JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { return new JSONException(message + toString()); }
throw syntaxError("Substring bounds error");
char c = x.nextClean(); char q; if (c == '[') { q = ')'; } else { throw x.syntaxError("A JSONArray text must start with '['"); if (x.nextClean() == ']') { return; x.back(); for (;;) { if (x.nextClean() == ',') { x.back(); this.m_myArrayList.add(null); } else { x.back(); this.m_myArrayList.add(x.nextValue()); c = x.nextClean(); switch (c) { case ';': case ',': if (x.nextClean() == ']') { return; x.back(); break;
/** * Determine if the source string still contains characters that next() * can consume.<p> * * @return true if not yet at the end of the source * @throws JSONException if something goes wrong */ public boolean more() throws JSONException { char nextChar = next(); if (nextChar == 0) { return false; } back(); return true; }
StringBuffer sb = new StringBuffer(); for (;;) { c = next(); switch (c) { case 0: case '\n': case '\r': throw syntaxError("Unterminated string"); case '\\': c = next(); switch (c) { case 'b': break; case 'u': sb.append((char)Integer.parseInt(next(4), 16)); break; case 'x': sb.append((char)Integer.parseInt(next(2), 16)); break; default:
/** * Construct a JSONArray from a source JSON text.<p> * * @param source a string that begins with * <code>[</code> <small>(left bracket)</small> * and ends with <code>]</code> <small>(right bracket)</small> * @throws JSONException if there is a syntax error */ public JSONArray(String source) throws JSONException { this(new JSONTokener(source)); }