JsonValue parse() throws IOException { // Braces for the root object are optional read(); skipWhiteSpace(); if (legacyRoot) { switch (current) { case '[': case '{': return checkTrailing(readValue()); default: try { // assume we have a root object without braces return checkTrailing(readObject(true)); } catch (Exception exception) { // test if we are dealing with a single JSON value instead (true/false/null/num/"") reset(); read(); skipWhiteSpace(); try { return checkTrailing(readValue()); } catch (Exception exception2) { } throw exception; // throw original error } } } else { return checkTrailing(readValue()); } }
JsonValue parse() throws IOException { // Braces for the root object are optional read(); skipWhiteSpace(); if (legacyRoot) { switch (current) { case '[': case '{': return checkTrailing(readValue()); default: try { // assume we have a root object without braces return checkTrailing(readObject(true)); } catch (Exception exception) { // test if we are dealing with a single JSON value instead (true/false/null/num/"") reset(); read(); skipWhiteSpace(); try { return checkTrailing(readValue()); } catch (Exception exception2) { } throw exception; // throw original error } } } else { return checkTrailing(readValue()); } }
private JsonArray readArray() throws IOException { read(); JsonArray array=new JsonArray(); skipWhiteSpace(); if (readIf(']')) { return array; } while (true) { skipWhiteSpace(); array.add(readValue()); skipWhiteSpace(); if (readIf(',')) skipWhiteSpace(); // , is optional if (readIf(']')) break; else if (isEndOfText()) throw error("End of input while parsing an array (did you forget a closing ']'?)"); } return array; }
private JsonArray readArray() throws IOException { read(); JsonArray array=new JsonArray(); skipWhiteSpace(); if (readIf(']')) { return array; } while (true) { skipWhiteSpace(); array.add(readValue()); skipWhiteSpace(); if (readIf(',')) skipWhiteSpace(); // , is optional if (readIf(']')) break; else if (isEndOfText()) throw error("End of input while parsing an array (did you forget a closing ']'?)"); } return array; }
private JsonObject readObject(boolean objectWithoutBraces) throws IOException { if (!objectWithoutBraces) read(); JsonObject object=new JsonObject(); skipWhiteSpace(); while (true) { if (objectWithoutBraces) { if (isEndOfText()) break; } else { if (isEndOfText()) throw error("End of input while parsing an object (did you forget a closing '}'?)"); if (readIf('}')) break; } String name=readName(); skipWhiteSpace(); if (!readIf(':')) { throw expected("':'"); } skipWhiteSpace(); object.add(name, readValue()); skipWhiteSpace(); if (readIf(',')) skipWhiteSpace(); // , is optional } return object; }
private JsonObject readObject(boolean objectWithoutBraces) throws IOException { if (!objectWithoutBraces) read(); JsonObject object=new JsonObject(); skipWhiteSpace(); while (true) { if (objectWithoutBraces) { if (isEndOfText()) break; } else { if (isEndOfText()) throw error("End of input while parsing an object (did you forget a closing '}'?)"); if (readIf('}')) break; } String name=readName(); skipWhiteSpace(); if (!readIf(':')) { throw expected("':'"); } skipWhiteSpace(); object.add(name, readValue()); skipWhiteSpace(); if (readIf(',')) skipWhiteSpace(); // , is optional } return object; }