public JSONArray names() { JSONArray ja = new JSONArray(); Iterator<String> keys = this.keys(); while (keys.hasNext()) { ja.put(keys.next()); } return ja.length() == 0 ? null : ja; }
static Writer writeValue(Writer writer, Object value) throws JSONException, IOException { if (value == null) { writer.write("null"); } else if (value instanceof JSONObject) { ((JSONObject) value).write(writer); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer); } else if (value instanceof Map) { Map<?, ?> map = (Map<?, ?>) value; new JSONObject(map).write(writer); } else if (value instanceof Collection) { Collection<?> coll = (Collection<?>) value; new JSONArray(coll).write(writer); } else if (value.getClass().isArray()) { new JSONArray(value).write(writer); } else if (value instanceof Number) { writer.write(numberToString((Number) value)); } else if (value instanceof Boolean) { writer.write(value.toString()); } else { quote(value.toString(), writer); } return writer; }