Example usage for org.json JSONObject write

List of usage examples for org.json JSONObject write

Introduction

In this page you can find the example usage for org.json JSONObject write.

Prototype

public Writer write(Writer writer) throws JSONException 

Source Link

Document

Write the contents of the JSONObject as JSON text to a writer.

Usage

From source file:org.elfinder.servlets.AbstractConnectorServlet.java

protected static void output(HttpServletResponse response, boolean isResponseTextHtml, JSONObject json,
        PrintWriter responseWriter) {
    // encoding was already set by servlet
    if (isResponseTextHtml) {
        response.setContentType("text/html; charset=UTF-8");
    } else {/*  ww w  .  ja  v a2s.co  m*/
        response.setContentType("application/json; charset=UTF-8");
    }

    try {
        json.write(responseWriter);
    } catch (Exception e) {
        logger.error("", e);
    }

    AbstractCommand.closeWriter(responseWriter);
}

From source file:org.hypertopic.RESTDatabase.java

protected static void writeBody(HttpURLConnection connection, JSONObject object) throws Exception {
    connection.setDoOutput(true);/*from w w w .  jav a2s . c o  m*/
    OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
    object.write(writer);
    writer.close();
}