private JSONObject parseJSONObject ( ) throws ParseException { expect ( ' ' ) ; skipWhitespace ( ) ; if ( peek ( ) == ' ' ) { // Empty object next ( ) ; return new JSONObject ( Collections . < Entry < String , Object > > emptyList ( ) ) ; } final List < Entry < String , Object > > kvPairs = new ArrayList <> ( ) ; final JSONObject jsonObject = new JSONObject ( kvPairs ) ; boolean first = true ; while ( peek ( ) != ' ' ) { if ( first ) { first = false ; } else { expect ( ' ' ) ; } final CharSequence key = parseString ( ) ; if ( key == null ) { throw new ParseException ( this , "Object keys must be strings" ) ; } if ( peek ( ) != ' ' ) { return null ; } expect ( ' ' ) ; final Object value = parseJSON ( ) ; // Check for special object id key if ( key . equals ( JSONUtils . ID_KEY ) ) { if ( value == null ) { throw new ParseException ( this , "Got null value for \"" + JSONUtils . ID_KEY + "\" key" ) ; } jsonObject . objectId = ( CharSequence ) value ; } else { kvPairs . add ( new SimpleEntry <> ( key . toString ( ) , value ) ) ; } } expect ( ' ' ) ; return jsonObject ; }
Parse a JSON Object .