mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-04 12:47:59 +08:00
add method
This commit is contained in:
parent
c00ab6e126
commit
4aee10da40
@ -331,6 +331,18 @@ public final class JSONUtil {
|
|||||||
return json.toJSONString(0);
|
return json.toJSONString(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转为JSON字符串,并写出到write
|
||||||
|
*
|
||||||
|
* @param json JSON
|
||||||
|
* @since 5.3.3
|
||||||
|
*/
|
||||||
|
public static void toJsonStr(JSON json, Writer writer) {
|
||||||
|
if (null != json) {
|
||||||
|
json.write(writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转为JSON字符串
|
* 转为JSON字符串
|
||||||
*
|
*
|
||||||
@ -354,12 +366,25 @@ public final class JSONUtil {
|
|||||||
if (null == obj) {
|
if (null == obj) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (obj instanceof String) {
|
if (obj instanceof CharSequence) {
|
||||||
return (String) obj;
|
return StrUtil.str((CharSequence) obj);
|
||||||
}
|
}
|
||||||
return toJsonStr(parse(obj));
|
return toJsonStr(parse(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换为JSON字符串并写出到writer
|
||||||
|
*
|
||||||
|
* @param obj 被转为JSON的对象
|
||||||
|
* @param writer Writer
|
||||||
|
* @since 5.3.3
|
||||||
|
*/
|
||||||
|
public static void toJsonStr(Object obj, Writer writer) {
|
||||||
|
if (null != obj) {
|
||||||
|
toJsonStr(parse(obj), writer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换为格式化后的JSON字符串
|
* 转换为格式化后的JSON字符串
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user