Code example for JSONObject

Methods: toString

0
    static protected void respond(HttpServletResponse response, JSONObject content) throws IOException, ServletException {
        if (content == null) {
            throw new ServletException("Content object can't be null"); 
        } 
         
        respond(response, content.toString());
    } 
 
    static protected void respond(HttpServletResponse response, String content) throws IOException, ServletException {
        if (response == null) {
            throw new ServletException("Response object can't be null"); 
        } 
         
        Writer w = response.getWriter();
        if (w != null) {
            w.write(content);
            w.flush();
            w.close();
        } else { 
            throw new ServletException("response returned a null writer"); 
        }