@ Override public WikipediaExample . Response < X > read ( JsonReader reader ) throws IOException { WikipediaExample . Response < X > pages = new WikipediaExample . Response < X > ( ) ; reader . beginObject ( ) ; while ( reader . hasNext ( ) ) { String nextName = reader . nextName ( ) ; if ( "query" . equals ( nextName ) ) { reader . beginObject ( ) ; while ( reader . hasNext ( ) ) { if ( query ( ) . equals ( reader . nextName ( ) ) ) { reader . beginObject ( ) ; while ( reader . hasNext ( ) ) { // each element is in form: "id" : { object } // this advances the pointer to the value and skips the key reader . nextName ( ) ; reader . beginObject ( ) ; pages . add ( build ( reader ) ) ; reader . endObject ( ) ; } reader . endObject ( ) ; } else { reader . skipValue ( ) ; } } reader . endObject ( ) ; } else if ( "continue" . equals ( nextName ) ) { reader . beginObject ( ) ; while ( reader . hasNext ( ) ) { if ( "gsroffset" . equals ( reader . nextName ( ) ) ) { pages . nextOffset = reader . nextLong ( ) ; } else { reader . skipValue ( ) ; } } reader . endObject ( ) ; } else { reader . skipValue ( ) ; } } reader . endObject ( ) ; return pages ; }
the wikipedia api doesn t use json arrays rather a series of nested objects .