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;
    }
@author Robert HG (254963746@qq.com) on 12/28/15.
lts-core/src/main/java/com/github/ltsopensource/json/JSONObject.java