public class JSONWriter extends Object implements Appendable, Flushable, Closeable
Writer
中。Constructor and Description |
---|
JSONWriter(Appendable appendable,
JSONFormatStyle formatStyle,
int level,
JSONConfig config,
Predicate<MutableEntry<Object,Object>> predicate)
构造
|
Modifier and Type | Method and Description |
---|---|
JSONWriter |
append(char c) |
JSONWriter |
append(CharSequence csq) |
JSONWriter |
append(CharSequence csq,
int start,
int end) |
JSONWriter |
beginArray()
JSONArray写出开始,默认写出"["
|
JSONWriter |
beginObj()
JSONObject写出开始,默认写出"{"
|
void |
close() |
JSONWriter |
endArray()
结束JSON数组,默认根据开始的类型,补充"]"
|
JSONWriter |
endObj()
结束JSON对象,默认根据开始的类型,补充"}"
|
void |
flush() |
JSONConfig |
getConfig()
获取JSON配置
|
static JSONWriter |
of(Appendable appendable,
int indentFactor,
int level,
JSONConfig config,
Predicate<MutableEntry<Object,Object>> predicate)
创建JSONWriter
|
static JSONWriter |
of(Appendable appendable,
int indentFactor,
JSONConfig config,
Predicate<MutableEntry<Object,Object>> predicate)
创建JSONWriter
|
String |
toString() |
JSONWriter |
writeField(MutableEntry<Object,Object> pair)
写出字段名及字段值,如果字段值是
null 且忽略null值,则不写出任何内容 |
void |
writeIndent(int count)
写出缩进
|
JSONWriter |
writeKey(String key)
写出键,自动处理分隔符和缩进,并包装键名
|
JSONWriter |
writeNewLine()
写出换行符
|
JSONWriter |
writeNumber(Number number)
|
void |
writeQuoteStrValue(String csq)
写出字符串值,并包装引号并转义字符
对所有双引号做转义处理(使用双反斜杠做转义) 为了能在HTML中较好的显示,会将</转义为<\/ JSON字符串中不能包含控制字符和未经转义的引号和反斜杠 |
JSONWriter |
writeRaw(String csq)
写入原始字符串值,不做任何处理
|
JSONWriter |
writeSpaceAfterSeparators()
写出空白字符,默认写出一个空格
|
public JSONWriter(Appendable appendable, JSONFormatStyle formatStyle, int level, JSONConfig config, Predicate<MutableEntry<Object,Object>> predicate)
appendable
- Appendable
formatStyle
- 格式化风格level
- 层级config
- JSON选项predicate
- 字段过滤器public static JSONWriter of(Appendable appendable, int indentFactor, JSONConfig config, Predicate<MutableEntry<Object,Object>> predicate)
appendable
- Appendable
indentFactor
- 缩进因子,定义每一级别增加的缩进量config
- JSON选项predicate
- predicate 字段过滤器public static JSONWriter of(Appendable appendable, int indentFactor, int level, JSONConfig config, Predicate<MutableEntry<Object,Object>> predicate)
appendable
- Appendable
indentFactor
- 缩进因子,定义每一级别增加的缩进量level
- 层级config
- JSON选项predicate
- predicate 字段过滤器public JSONConfig getConfig()
JSONConfig
public JSONWriter beginObj()
public JSONWriter endObj()
public JSONWriter beginArray()
public JSONWriter endArray()
public JSONWriter writeField(MutableEntry<Object,Object> pair)
null
且忽略null值,则不写出任何内容pair
- 键值对public JSONWriter writeKey(String key)
key
- 键名public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public void writeQuoteStrValue(String csq)
csq
- 字符串public JSONWriter writeSpaceAfterSeparators()
public void writeIndent(int count)
count
- 空格数public JSONWriter writeNewLine()
public JSONWriter writeRaw(String csq)
csq
- 字符串public JSONWriter writeNumber(Number number)
number
- 数字public JSONWriter append(char c) throws IORuntimeException
append
in interface Appendable
IORuntimeException
public JSONWriter append(CharSequence csq) throws IORuntimeException
append
in interface Appendable
IORuntimeException
public JSONWriter append(CharSequence csq, int start, int end) throws IORuntimeException
append
in interface Appendable
IORuntimeException
Copyright © 2025. All rights reserved.