Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.

JSON_writeJSONString_cn

wenshao edited this page May 2, 2016 · 2 revisions

在1.2.11版本中,JSON类新增对OutputStream/Writer直接支持。

packagecom.alibaba.fastjson;
publicabstractclassJSON {
publicstaticfinalintwriteJSONString(OutputStreamos, // Objectobject, // SerializerFeature... features) throwsIOException;
publicstaticfinalintwriteJSONString(OutputStreamos, //Charsetcharset, // Objectobject, // SerializerFeature... features) throwsIOException;
publicstaticfinalintwriteJSONString(Writeros, // Objectobject, // SerializerFeature... features) throwsIOException;
}

Sample

importcom.alibaba.fastjson;
importjava.nio.charset.Charset;
classModel {
publicintvalue;
}
Modelmodel = newModel();
model.value = 1001;
OutputStreamos = ...;
JSON.writeJSONString(os, model);
JSON.writeJSONString(os, Charset.from("GB18030"), model);
Writerwriter = ...;
JSON.writeJSONString(os, model);

Clone this wiki locally