/** * Make a prettyprinted JSON text of this JSONObject. * <p> * Warning: This method assumes that the data structure is acyclical. * @param indentFactor The number of spaces to add to each level of * indentation. * @return a printable, displayable, portable, transmittable * representation of the object, beginning * with <code>{</code> <small>(left brace)</small> and ending * with <code>}</code> <small>(right brace)</small>. * @throws JSONException If the object contains an invalid number. */ public String toString(int indentFactor) throws JSONException { return toString(indentFactor, 0); }
/** * Writes the string representation of {@link JSONObject} defined through {@link #getJSONObjectProperty()} * to {@link javax.servlet.http.HttpServletResponse}'s outputstream. * * @param invocation * @throws Exception */ public void execute(ActionInvocation invocation) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("executing JSONResult"); } JSONObject jsonObject = getJSONObject(invocation); if (jsonObject != null) { final String json = jsonObject.toString(); final HttpServletResponse response = getServletResponse(invocation); final Charset charset = StandardCharsets.UTF_8; final byte[] content = json.getBytes(charset.name()); response.setContentType(getContentType() + ";charset=" + charset.name()); response.setContentLength(content.length); final OutputStream os = response.getOutputStream(); os.write(content); os.flush(); if (LOG.isDebugEnabled()) { LOG.debug("written ["+json+"] to HttpServletResponse outputstream"); } } }
if (methodType != Request.MethodType.GET && data != null) request.setRequestBody(data.toString());
return new JSONObject((Map)value).toString();