本文整理了Java中org.json.JSONObject.write()
方法的一些代码示例,展示了JSONObject.write()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.write()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:write
[英]Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added.
Warning: This method assumes that the data structure is acyclical.
[中]将JSONObject的内容作为JSON文本写入编写器。对于紧凑性,不添加空格。
警告:此方法假定数据结构是非循环的。
代码示例来源:origin: zzz40500/GsonFormat
/**
* Write the contents of the JSONObject 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);
}
代码示例来源:origin: loklak/loklak_server
/**
* Write the contents of the JSONObject 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);
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* 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 {
StringWriter w = new StringWriter();
synchronized (w.getBuffer()) {
return this.write(w, indentFactor, 0).toString();
}
}
代码示例来源:origin: loklak/loklak_server
StringWriter w = new StringWriter();
synchronized (w.getBuffer()) {
return this.write(w, indentFactor, 0).toString();
代码示例来源:origin: loklak/loklak_server
private JsonCapsuleFactory(JSONObject jo) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
GZIPOutputStream out = null; try {out = new GZIPOutputStream(baos, 1024){{def.setLevel(Deflater.BEST_COMPRESSION);}};} catch (IOException e) {}
OutputStreamWriter osw = new OutputStreamWriter(out);
jo.write(osw);
try {osw.close();} catch (IOException e) {}
//byte[] b = new ObjectMapper().writer().writeValueAsBytes(json);
//byte[] c = Compression.gzip(b);
byte[] c = baos.toByteArray();
//if (b.length <= c.length) {
// this.capsule = new byte[b.length + 1];
// this.capsule[0] = 0;
// System.arraycopy(b, 0, this.capsule, 1, b.length);
//} else {
this.capsule = new byte[c.length + 1];
this.capsule[0] = 1;
System.arraycopy(c, 0, this.capsule, 1, c.length);
//}
//System.out.print("DEBUG " + this.getRawJson());
}
代码示例来源:origin: zzz40500/GsonFormat
writer.write("null");
} else if (value instanceof JSONObject) {
((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,
代码示例来源:origin: loklak/loklak_server
writer.write(quote(((Enum<?>)value).name()));
} else if (value instanceof JSONObject) {
((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;
new JSONObject(map).write(writer, indentFactor, indent);
} else if (value instanceof Collection) {
Collection<?> coll = (Collection<?>) value;
代码示例来源:origin: b3log/latke
/**
* Write the contents of the JSONObject 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);
}
代码示例来源:origin: ralfstx/minimal-json
@Override
public void writeToWriter(Object model, Writer writer) throws Exception {
((JSONObject)model).write(writer);
}
代码示例来源:origin: b3log/latke
StringWriter w = new StringWriter();
synchronized (w.getBuffer()) {
return this.write(w, indentFactor, 0).toString();
代码示例来源:origin: b3log/latke
writer.write(quote(((Enum<?>)value).name()));
} else if (value instanceof JSONObject) {
((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;
new JSONObject(map).write(writer, indentFactor, indent);
} else if (value instanceof Collection) {
Collection<?> coll = (Collection<?>) value;
代码示例来源:origin: org.codeartisans/org.json
/**
* Write the contents of the JSONObject 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);
}
代码示例来源:origin: io.snappydata/gemfire-util
/**
* Write the contents of the JSONObject 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);
}
代码示例来源:origin: io.snappydata/gemfire-json
/**
* Write the contents of the JSONObject 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);
}
代码示例来源:origin: aruld/java-oneliners
/**
* Write the contents of the JSONObject 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);
}
代码示例来源:origin: rchodava/datamill
private static void write(OutputStream outputStream, JSONObject json) {
logger.debug("Returning {} response", json.get(STATUS_CODE));
if (logger.isTraceEnabled()) {
logger.trace("Response: {}", json);
}
try (OutputStreamWriter writer = new OutputStreamWriter(outputStream, Charsets.UTF_8)) {
json.write(writer);
} catch (IOException e) {
logger.debug("Error while closing output response");
}
}
代码示例来源:origin: ca.carleton.gcrc/nunaliit2-dbWeb
private void sendJsonResponse(HttpServletResponse response, JSONObject result) throws Exception {
response.setStatus(HttpServletResponse.SC_OK);
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", (new Date()).getTime());
response.setContentType("text/plain");
response.setCharacterEncoding("utf-8");
OutputStreamWriter osw = new OutputStreamWriter( response.getOutputStream(), "UTF-8" );
result.write(osw);
osw.flush();
}
代码示例来源:origin: net.adamcin.oakpal/oakpal-core
public static void writeReportsToWriter(Collection<CheckReport> reports, Writer writer) throws IOException, JSONException {
JSONArray jsonReports = reportsToJSON(reports);
JSONObject rootObj = new JSONObject();
rootObj.put(KEY_REPORTS, jsonReports);
rootObj.write(writer, 2, 0);
writer.flush();
}
代码示例来源:origin: org.qcri.rheem/rheem-core
/**
* Writes the measuremnt to the {@link #repositoryPath}.
*/
private void write(JSONObject jsonMeasurement) {
try {
jsonMeasurement.write(this.getWriter());
writer.write('\n');
} catch (IOException e) {
IOUtils.closeQuietly(this.writer);
throw new RuntimeException("Could not open cardinality repository file for writing.", e);
}
}
代码示例来源:origin: org.qcri.rheem/rheem-core
/**
* Writes the measuremnt to the {@link #repositoryPath}.
*/
private void write(JSONObject jsonMeasurement) throws IOException {
jsonMeasurement.write(this.getWriter());
writer.write('\n');
}
内容来源于网络,如有侵权,请联系作者删除!