/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p><b> * Warning: This method assumes that the data structure is acyclical. *</b> * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Make a prettyprinted JSON text of this JSONArray. 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, transmittable representation of the * object, beginning with <code>[</code> <small>(left * bracket)</small> and ending with <code>]</code> * <small>(right bracket)</small>. * @throws JSONException */ public String toString(int indentFactor) throws JSONException { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString(); } }
StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString();
((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { new JSONObject((Map<String, Object>) value).write(writer, indentFactor, indent); } else if (value instanceof Collection) { new JSONArray((Collection<Object>) value).write(writer, indentFactor, indent); } else if (value.getClass().isArray()) { new JSONArray(value).write(writer, indentFactor, indent); } else if (value instanceof Number) { writer.write(numberToString((Number) value));
((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { Map<?, ?> map = (Map<?, ?>) value; } else if (value instanceof Collection) { Collection<?> coll = (Collection<?>) value; new JSONArray(coll).write(writer, indentFactor, indent); } else if (value.getClass().isArray()) { new JSONArray(value).write(writer, indentFactor, indent); } else { quote(value.toString(), writer);
/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p><b> * Warning: This method assumes that the data structure is acyclical. *</b> * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString();
((JSONObject) value).write(writer, indentFactor, indent); } else if (value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); } else if (value instanceof Map) { Map<?, ?> map = (Map<?, ?>) value; } else if (value instanceof Collection) { Collection<?> coll = (Collection<?>) value; new JSONArray(coll).write(writer, indentFactor, indent); } else if (value.getClass().isArray()) { new JSONArray(value).write(writer, indentFactor, indent); } else { quote(value.toString(), writer);
/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p> * Warning: This method assumes that the data structure is acyclical. * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Write the contents of the JSONArray as JSON text to a writer. For * compactness, no whitespace is added. * <p><b> * Warning: This method assumes that the data structure is acyclical. *</b> * * @return The writer. * @throws JSONException */ public Writer write(Writer writer) throws JSONException { return this.write(writer, 0, 0); }
/** * Make a prettyprinted JSON text of this JSONArray. * 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, transmittable * representation of the object, beginning * with <code>[</code> <small>(left bracket)</small> and ending * with <code>]</code> <small>(right bracket)</small>. * @throws JSONException */ public String toString(int indentFactor) throws JSONException { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString(); } }
/** * Make a prettyprinted JSON text of this JSONArray. * 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, transmittable * representation of the object, beginning * with <code>[</code> <small>(left bracket)</small> and ending * with <code>]</code> <small>(right bracket)</small>. * @throws JSONException */ public String toString(int indentFactor) throws JSONException { StringWriter sw = new StringWriter(); synchronized (sw.getBuffer()) { return this.write(sw, indentFactor, 0).toString(); } }
private void sendJsonResponse(JSONArray array, HttpServletResponse response) throws ServletException { response.setCharacterEncoding("UTF-8"); response.setContentType("text/javascript"); response.setHeader("Cache-Control", "no-cache,must-revalidate"); response.setDateHeader("Expires", (new Date()).getTime()); try { OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream(),"UTF-8"); array.write(osw); osw.flush(); } catch(Exception e) { throw new ServletException("Failure generating error",e); } }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Sistema instanciaSys = Sistema.darInstancia(); instanciaSys.inicializarSistema(6); Esquina[] esquinas = instanciaSys.getEsquinas(); JSONArray json =new JSONArray(); for (Esquina esquina : esquinas) { JSONObject jO = new JSONObject(); jO.put("coordX", esquina.getCoordX()); jO.put("coordY", esquina.getCoordY()); json.put(jO); } // tell the client that JSON is coming response.setContentType("application/json"); resposne.setCharacterEncoding("UTF-8"); json.write(response.getWriter()); }
/** * Outputs a {@code JSONArray} to out. */ public <A extends Appendable> A append(A out, GxpContext gxpContext, JSONArray value) throws IOException { Preconditions.checkNotNull(value); StringWriter sw = new StringWriter(); try { value.write(sw); } catch (JSONException e) { throw new IOException(e); } out.append(sw.toString()); return out; }