问问题
625 次
1 回答
1
根据源代码:
public String toString() {
try {
return this.toString(0);
} catch (Exception e) {
return null;
}
}
public String toString(int indentFactor) throws JSONException {
StringWriter w = new StringWriter();
synchronized (w.getBuffer()) {
return this.write(w, indentFactor, 0).toString();
}
}
public Writer write(Writer writer) throws JSONException {
return this.write(writer, 0, 0);
}
所以基本上,第一种方法:
myWriter.write(myJSONObj.toString());
- 创建一个
StringWriter
. - 传作家到
write(Writer writer, int indentFactor, int indent)
。 - JSON 内容被写入编写器。
- writer 的内容通过
StringWriter#toString()
. - 最后的字符串被写入
myWriter
.
第二种方法:
myJSONObj.write(myWriter);
- 传作家到
write(Writer writer, int indentFactor, int indent)
。 - JSON 内容被写入编写器。
于 2013-10-09T19:46:43.317 回答