According to the source code :
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으로 콘텐츠를 GET 작가에게 씁니다.
- 작가는
StringWriter#toString()
을 통해 변환됩니다.
- 마지막 문자열은
myWriter
에 기록됩니다.
두 번째 방법 :
myJSONObj.write(myWriter);
- 는
write(Writer writer, int indentFactor, int indent)
에 작가를 전달합니다.
- JSON 콘텐츠가 작성자에게 쓰여집니다.
어떤 라이브러리를 사용하십니까? –
org.json.JSONObject – 0x56794E