private List parseArray ( JsonLexer lexer ) { List content = new ArrayList ( ) ; JsonToken currentToken ; for ( ; ; ) { currentToken = lexer . nextToken ( ) ; if ( currentToken == null ) { throw new JsonException ( "Expected a value on line: " + lexer . getReader ( ) . getLine ( ) + ", " + "column: " + lexer . getReader ( ) . getColumn ( ) + ".\n" + "But got an unterminated array." ) ; } if ( currentToken . getType ( ) == OPEN_CURLY ) { content . add ( parseObject ( lexer ) ) ; } else if ( currentToken . getType ( ) == OPEN_BRACKET ) { content . add ( parseArray ( lexer ) ) ; } else if ( currentToken . getType ( ) . ordinal ( ) >= NULL . ordinal ( ) ) { content . add ( currentToken . getValue ( ) ) ; } else if ( currentToken . getType ( ) == CLOSE_BRACKET ) { return content ; } else { throw new JsonException ( "Expected a value, an array, or an object " + "on line: " + currentToken . getStartLine ( ) + ", " + "column: " + currentToken . getStartColumn ( ) + ".\n" + "But got '" + currentToken . getText ( ) + "' instead." ) ; } currentToken = lexer . nextToken ( ) ; if ( currentToken == null ) { throw new JsonException ( "Expected " + CLOSE_BRACKET . getLabel ( ) + " " + "or " + COMMA . getLabel ( ) + " " + "on line: " + lexer . getReader ( ) . getLine ( ) + ", " + "column: " + lexer . getReader ( ) . getColumn ( ) + ".\n" + "But got an unterminated array." ) ; } // Expect a comma for an upcoming value // or a closing bracket for the end of the array if ( currentToken . getType ( ) == CLOSE_BRACKET ) { break ; } else if ( currentToken . getType ( ) != COMMA ) { throw new JsonException ( "Expected a value or " + CLOSE_BRACKET . getLabel ( ) + " " + "on line: " + currentToken . getStartLine ( ) + " " + "column: " + currentToken . getStartColumn ( ) + ".\n" + "But got '" + currentToken . getText ( ) + "' instead." ) ; } } return content ; }
Parse an array from the lexer