Append a key. The key will be associated with the next value. In an object, every value must be preceded by a key. @param string A key string. @return this @throws JSONException If the key is out of place. For example, keys do not belong in arrays or if the key is null.
(String string)
| 199 | * do not belong in arrays or if the key is null. |
| 200 | */ |
| 201 | public JSONWriter key(String string) throws JSONException { |
| 202 | if (string == null) { |
| 203 | throw new JSONException("Null key."); |
| 204 | } |
| 205 | if (this.mode == 'k') { |
| 206 | try { |
| 207 | stack[top - 1].putOnce(string, Boolean.TRUE); |
| 208 | if (this.comma) { |
| 209 | this.writer.write(','); |
| 210 | } |
| 211 | this.writer.write(JSONObject.quote(string)); |
| 212 | this.writer.write(':'); |
| 213 | this.comma = false; |
| 214 | this.mode = 'o'; |
| 215 | return this; |
| 216 | } catch (IOException e) { |
| 217 | throw new JSONException(e); |
| 218 | } |
| 219 | } |
| 220 | throw new JSONException("Misplaced key."); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | /** |