public class JSON extends Object
Modifier and Type | Field and Description |
---|---|
static String |
JSON_CONVERT_ESCAPE_CHAR |
Constructor and Description |
---|
JSON() |
Modifier and Type | Method and Description |
---|---|
static String |
fixJSON(String jsonStr)
修复 JSON 字符串中因清理节点导致的多个","的分割异常问题
|
static String |
formatJson(String jsonStr)
格式化 JSON
|
static boolean |
isConvertEscapeChar()
是否进行 EscapeChar 的转换
|
static boolean |
isJSON(String jsonStr)
判断是否是 JSON 的可解析
|
static boolean |
isJSONList(String jsonStr)
判断是否是 JSON 的 list/array 类型
|
static boolean |
isJSONMap(String jsonStr)
判断是否是 JSON 的 map 类型
|
static Object |
parse(String jsonStr)
解析 JSON 字符串
如果是{}包裹的字符串解析成 HashMap,如果是[]包裹的字符串解析成 ArrayList
|
static String |
removeNode(String jsonStr,
String... fields)
不考虑层级, 清除 JSON 中指定的 field
|
static String |
removeNullNode(String jsonStr)
清理json字符串串null节点
|
static String |
replaceNode(String jsonStr,
String field,
Object obj)
替换 json 中的节点
|
static void |
setConvertEscapeChar(boolean convertEscapeChar)
设置是否进行 EscapeChar 的转换
|
static String |
shrink(String jsonStr,
boolean withLineSeparator)
收缩 JSON 字符串
移除制表符空格等不可见字符
|
static String |
toJSON(Object object)
将 Java 对象 转换成 JSON字符串
|
static String |
toJSON(Object object,
boolean allField)
将 Java 对象 转换成 JSON字符串
|
static String |
toJSON(Object object,
boolean convertEscapeChar,
boolean allField)
将 Java 对象 转换成 JSON字符串
|
static String |
toJSONWithFormat(Object object)
将 Java 对象 转换成 JSON字符串, 并格式化
|
static String |
toJSONWithFormat(Object object,
boolean allField)
将 Java 对象 转换成 JSON字符串, 并格式化
|
static <T> T |
toObject(String jsonStr,
Type type)
将 JSON字符串 转换成 Java 对象,默认严格限制字段大小写
|
static <T> T |
toObject(String jsonStr,
Type type,
boolean ignoreCase)
将 JSON字符串 转换成 Java 对象
|
public static final String JSON_CONVERT_ESCAPE_CHAR
public static boolean isConvertEscapeChar()
public static void setConvertEscapeChar(boolean convertEscapeChar)
convertEscapeChar
- true: 是, false: 否public static String toJSON(Object object)
object
- 待转换的对象public static String toJSON(Object object, boolean allField)
object
- 待转换的对象allField
- 是否序列化所有的属性public static String toJSONWithFormat(Object object)
object
- 待转换的对象public static String toJSONWithFormat(Object object, boolean allField)
object
- 待转换的对象allField
- 是否序列化所有的属性public static String toJSON(Object object, boolean convertEscapeChar, boolean allField)
object
- 待转换的对象convertEscapeChar
- 是否转换转义字符allField
- 是否序列化所有的属性public static <T> T toObject(String jsonStr, Type type, boolean ignoreCase)
T
- 范型jsonStr
- 待转换的 JSON 字符串type
- 转换的目标 java 类ignoreCase
- 是否忽略字段大小写public static <T> T toObject(String jsonStr, Type type)
T
- 范型jsonStr
- 待转换的 JSON 字符串type
- 转换的目标 java 类public static Object parse(String jsonStr)
jsonStr
- 待解析的 JSON 字符串public static String formatJson(String jsonStr)
jsonStr
- JSON 字符串public static String removeNullNode(String jsonStr)
jsonStr
- json 字符串public static String removeNode(String jsonStr, String... fields)
jsonStr
- json 字符串fields
- 被清除的 fieldpublic static String replaceNode(String jsonStr, String field, Object obj)
jsonStr
- json 字符串field
- 被替换的属性名obj
- 替换的对象public static String shrink(String jsonStr, boolean withLineSeparator)
jsonStr
- 被收缩的字符串withLineSeparator
- 是否移除换行符public static String fixJSON(String jsonStr)
jsonStr
- json 字符串public static boolean isJSONMap(String jsonStr)
jsonStr
- 目标字符串public static boolean isJSONList(String jsonStr)
jsonStr
- 目标字符串public static boolean isJSON(String jsonStr)
jsonStr
- 目标字符串Copyright © 2020 Voovan. All rights reserved.