public class JSONWriter extends Writer
Writer中。| 构造器和说明 |
|---|
JSONWriter(Writer writer,
int indentFactor,
int indent,
JSONConfig config)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
JSONWriter |
beginArray()
JSONArray写出开始,默认写出"["
|
JSONWriter |
beginObj()
JSONObject写出开始,默认写出"{"
|
void |
close() |
JSONWriter |
end()
结束,默认根据开始的类型,补充"}"或"]"
|
void |
flush() |
static JSONWriter |
of(Writer writer,
int indentFactor,
int indent,
JSONConfig config)
创建JSONWriter
|
void |
write(char[] cbuf,
int off,
int len) |
JSONWriter |
writeField(String key,
Object value)
写出字段名及字段值,如果字段值是
null且忽略null值,则不写出任何内容 |
JSONWriter |
writeKey(String key)
写出键,自动处理分隔符和缩进,并包装键名
|
JSONWriter |
writeValue(Object value)
|
public JSONWriter(Writer writer, int indentFactor, int indent, JSONConfig config)
writer - WriterindentFactor - 缩进因子,定义每一级别增加的缩进量indent - 本级别缩进量config - JSON选项public static JSONWriter of(Writer writer, int indentFactor, int indent, JSONConfig config)
writer - WriterindentFactor - 缩进因子,定义每一级别增加的缩进量indent - 本级别缩进量config - JSON选项public JSONWriter beginObj()
public JSONWriter beginArray()
public JSONWriter end()
public JSONWriter writeKey(String key)
key - 键名public JSONWriter writeValue(Object value)
value - 值public JSONWriter writeField(String key, Object value)
null且忽略null值,则不写出任何内容key - 字段名value - 字段值public void write(char[] cbuf,
int off,
int len)
throws IOException
write 在类中 WriterIOExceptionpublic void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableclose 在类中 WriterIOExceptionCopyright © 2022. All rights reserved.