peek Json
Returns a new JsonReader that can read data from this JsonReader without consuming it. The returned reader becomes invalid once this one is next read or closed.
For example, we can use peekJson() to lookahead and read the same data multiple times.
Buffer buffer = new Buffer();
buffer.writeUtf8("[123, 456, 789]")
JsonReader jsonReader = JsonReader.of(buffer);
jsonReader.beginArray();
jsonReader.nextInt(); // Returns 123, reader contains 456, 789 and ].
JsonReader peek = reader.peekJson();
peek.nextInt() // Returns 456.
peek.nextInt() // Returns 789.
peek.endArray()
jsonReader.nextInt() // Returns 456, reader contains 789 and ].
Content copied to clipboard