public JSONWriter keySymbolValuePair ( String aKey , String aValue ) throws JSONException { assert ( aKey != null ) ; assert ( m_mode == ' ' ) ; // The key should not have already been seen in this scope. assert ( m_scopeStack [ m_top ] . add ( aKey ) ) ; try { m_writer . write ( m_expectingComma ? ",\"" : "\"" ) ; m_writer . write ( aKey ) ; if ( aValue == null ) { m_writer . write ( "\":null" ) ; } else { m_writer . write ( "\":\"" ) ; m_writer . write ( JSONObject . quotable ( aValue ) ) ; m_writer . write ( ' ' ) ; } } catch ( IOException e ) { throw new JSONException ( e ) ; } m_expectingComma = true ; return this ; }
Write a JSON key - value pair in one optimized step that assumes that the key is a symbol composed of normal characters requiring no escaping and asserts that keys are non - null and unique within an object ONLY if asserts are enabled . This method is most suitable in the common case where the caller is making a hard - coded series of calls with the same hard - coded strings for keys . Any sequencing errors can be detected in debug runs with asserts enabled .