Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added. Warning: This method assumes that the data structure is acyclical. @return The writer. @throws JSONException
(Writer writer)
| 1600 | * @throws JSONException |
| 1601 | */ |
| 1602 | public Writer write(Writer writer) throws JSONException { |
| 1603 | try { |
| 1604 | boolean commanate = false; |
| 1605 | Iterator keys = keys(); |
| 1606 | writer.write('{'); |
| 1607 | |
| 1608 | while (keys.hasNext()) { |
| 1609 | if (commanate) { |
| 1610 | writer.write(','); |
| 1611 | } |
| 1612 | Object key = keys.next(); |
| 1613 | writer.write(quote(key.toString())); |
| 1614 | writer.write(':'); |
| 1615 | Object value = this.map.get(key); |
| 1616 | if (value instanceof JSONObject) { |
| 1617 | ((JSONObject)value).write(writer); |
| 1618 | } else if (value instanceof JSONArray) { |
| 1619 | ((JSONArray)value).write(writer); |
| 1620 | } else { |
| 1621 | writer.write(valueToString(value)); |
| 1622 | } |
| 1623 | commanate = true; |
| 1624 | } |
| 1625 | writer.write('}'); |
| 1626 | return writer; |
| 1627 | } catch (IOException exception) { |
| 1628 | throw new JSONException(exception); |
| 1629 | } |
| 1630 | } |
| 1631 | } |