public JSONObject(JSONTokener x) : this() { char c; String key; if (x.nextClean() != '{') { throw x.syntaxError("A JSONObject text must begin with '{'"); } for (;;) { c = x.nextClean(); if (c.Equals(Convert.ToChar(0))) { throw x.syntaxError("A JSONObject text must end with '}'"); } switch (c) { case '}': return; default: x.back(); key = x.nextValue().ToString(); break; } // The key is followed by ':'. c = x.nextClean(); if (c != ':') { throw x.syntaxError("Expected a ':' after a key"); } this.putOnce(key, x.nextValue()); // Pairs are separated by ','. switch (x.nextClean()) { case ';': case ',': if (x.nextClean() == '}') { return; } x.back(); break; case '}': return; default: throw x.syntaxError("Expected a ',' or '}'"); } } }
/** * Construct a JSONArray from a JSONTokener. * * @param x * A JSONTokener * @ * If there is a syntax error. */ public JSONArray(JSONTokener x) : this() { if (x.nextClean() != '[') { throw x.syntaxError("A JSONArray text must start with '['"); } if (x.nextClean() != ']') { x.back(); for (;;) { if (x.nextClean() == ',') { x.back(); this.myArrayList.Add(JSONObject.NULL); } else { x.back(); this.myArrayList.Add(x.nextValue()); } switch (x.nextClean()) { case ',': if (x.nextClean() == ']') { return; } x.back(); break; case ']': return; default: throw x.syntaxError("Expected a ',' or ']'"); } } } }