Parses the complete JSON string provided by the reader into a parse tree. An exception is thrown if the JSON string has multiple top-level JSON elements, or if there is trailing data. <p>The JSON data is parsed in {@linkplain JsonReader#setStrictness(Strictness) lenient mode}. @param reader JSON t
(Reader reader)
| 105 | * @since 2.8.6 |
| 106 | */ |
| 107 | public static JsonElement parseReader(Reader reader) throws JsonIOException, JsonSyntaxException { |
| 108 | try { |
| 109 | JsonReader jsonReader = new JsonReader(reader); |
| 110 | JsonElement element = parseReader(jsonReader); |
| 111 | if (!element.isJsonNull() && jsonReader.peek() != JsonToken.END_DOCUMENT) { |
| 112 | throw new JsonSyntaxException("Did not consume the entire document."); |
| 113 | } |
| 114 | return element; |
| 115 | } catch (MalformedJsonException | NumberFormatException e) { |
| 116 | throw new JsonSyntaxException(e); |
| 117 | } catch (IOException e) { |
| 118 | throw new JsonIOException(e); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns the next value from the JSON stream as a parse tree. Unlike the other {@code parse} |