public class JSONWriter extends Writer
Writer中。| Constructor and Description |
|---|
JSONWriter(Writer writer,
int indentFactor,
int indent,
JSONConfig config)
构造
|
| Modifier and Type | Method and Description |
|---|---|
JSONWriter |
beginArray()
JSONArray写出开始,默认写出"["
|
JSONWriter |
beginObj()
JSONObject写出开始,默认写出"{"
|
void |
close() |
JSONWriter |
end()
结束,默认根据开始的类型,补充"}"或"]"
|
void |
flush() |
JSONConfig |
getConfig()
获取JSON配置
|
static JSONWriter |
of(Writer writer,
int indentFactor,
int indent,
JSONConfig config)
创建JSONWriter
|
void |
write(char[] cbuf,
int off,
int len) |
JSONWriter |
writeField(MutableEntry<Object,Object> pair,
Predicate<MutableEntry<Object,Object>> predicate)
|
JSONWriter |
writeKey(String key)
写出键,自动处理分隔符和缩进,并包装键名
|
JSONWriter |
writeLF()
写出换行符
|
void |
writeQuoteStrValue(String csq)
写出字符串值,并包装引号并转义字符
对所有双引号做转义处理(使用双反斜杠做转义) 为了能在HTML中较好的显示,会将</转义为<\/ JSON字符串中不能包含控制字符和未经转义的引号和反斜杠 |
JSONWriter |
writeRaw(char c)
写入原始字符值,不做任何处理
|
JSONWriter |
writeRaw(String csq)
写入原始字符串值,不做任何处理
|
void |
writeSpace(int count)
写出空格
|
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 JSONConfig getConfig()
JSONConfigpublic JSONWriter beginObj()
public JSONWriter beginArray()
public JSONWriter end()
public JSONWriter writeField(MutableEntry<Object,Object> pair, Predicate<MutableEntry<Object,Object>> predicate)
pair - 键值对predicate - 过滤修改器public JSONWriter writeKey(String key)
key - 键名public void write(char[] cbuf,
int off,
int len)
throws IOException
write in class WriterIOExceptionpublic void flush()
public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class WriterIOExceptionpublic void writeQuoteStrValue(String csq)
csq - 字符串public void writeSpace(int count)
count - 空格数public JSONWriter writeLF()
public JSONWriter writeRaw(String csq)
csq - 字符串public JSONWriter writeRaw(char c)
c - 字符Copyright © 2024. All rights reserved.