reader.beginArray(); while (reader.hasNext()) { array.add(parseRecursive(reader)); reader.beginObject(); while (reader.hasNext()) { object.add(reader.nextName(), parseRecursive(reader));
/** * Takes a reader in any state and returns the next value as a JsonElement. */ public static JsonElement parse(JsonReader reader) throws JsonParseException { boolean isEmpty = true; try { reader.peek(); isEmpty = false; return parseRecursive(reader); } catch (EOFException e) { /* * For compatibility with JSON 1.5 and earlier, we return a JsonNull for * empty documents instead of throwing. */ if (isEmpty) { return JsonNull.INSTANCE; } throw new JsonIOException(e); } catch (MalformedJsonException e) { throw new JsonSyntaxException(e); } catch (IOException e) { throw new JsonIOException(e); } catch (NumberFormatException e) { throw new JsonSyntaxException(e); } }