/** * Returns the next value from the input. * * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean, * Integer, Long, Double or {@link JSONObject#NULL}. * @throws RuntimeException if the input is malformed. */ Object nextValue(Class<?> desiredType) { int c = nextCleanInternal(); if (JSONObject.class.equals(desiredType) && c != '{'){ throw syntaxError("A JSONObject text must begin with '{'"); } if (JSONArray.class.equals(desiredType) && c != '['){ throw syntaxError("A JSONArray text must start with '['"); } switch (c) { case -1: throw syntaxError("End of input"); case '{': return readObject(); case '[': return readArray(); case '\'': case '"': return nextString((char) c); default: pos--; return readLiteral(); } }
/** * Returns the next value from the input. * * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean, * Integer, Long, Double or {@link JSONObject#NULL}. * @throws RuntimeException if the input is malformed. */ Object nextValue(Class<?> desiredType) { int c = nextCleanInternal(); if (JSONObject.class.equals(desiredType) && c != '{'){ throw syntaxError("A JSONObject text must begin with '{'"); } if (JSONArray.class.equals(desiredType) && c != '['){ throw syntaxError("A JSONArray text must start with '['"); } switch (c) { case -1: throw syntaxError("End of input"); case '{': return readObject(); case '[': return readArray(); case '\'': case '"': return nextString((char) c); default: pos--; return readLiteral(); } }