public class JSONUtil extends Object
| 构造器和说明 |
|---|
JSONUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static JSONArray |
createArray()
创建 JSONArray
|
static JSONObject |
createObj()
创建JSONObject
|
protected static void |
indent(Writer writer,
int indent)
缩进,使用空格符
|
protected static String |
numberToString(Number number)
Produce a string from a Number.
|
static JSON |
parse(Object obj)
转换对象为JSON
支持的对象: String: 转换为相应的对象 Array Collection:转换为JSONArray Bean对象:转为JSONObject |
static JSONArray |
parseArray(String jsonStr)
JSON字符串转JSONArray
|
static JSONObject |
parseObj(String jsonStr)
JSON字符串转JSONObject对象
|
static String |
quote(String string)
对所有双引号做转义处理(使用双反斜杠做转义)
为了能在HTML中较好的显示,会将</转义为<\/ JSON字符串中不能包含控制字符和未经转义的引号和反斜杠 |
static Writer |
quote(String string,
Writer writer)
对所有双引号做转义处理(使用双反斜杠做转义)
为了能在HTML中较好的显示,会将</转义为<\/ JSON字符串中不能包含控制字符和未经转义的引号和反斜杠 |
protected static Object |
stringToValue(String string)
Try to convert a string into a number, boolean, or null.
|
protected static void |
testValidity(Object obj)
如果对象是Number 且是 NaN or infinite,将抛出异常
|
static <T> T |
toBean(JSONObject json,
Class<T> beanClass)
转为实体类对象
|
static String |
toJsonPrettyStr(JSON json)
转为JSON字符串
|
static String |
toJsonPrettyStr(Object obj)
转换为格式化后的JSON字符串
|
static String |
toJsonStr(JSON json)
转为JSON字符串
|
static String |
toJsonStr(JSON json,
int indentFactor)
转为JSON字符串
|
static String |
toJsonStr(Object obj)
转换为JSON字符串
|
protected static String |
valueToString(Object value)
Make a JSON text of an Object value.
|
static Object |
wrap(Object object)
在需要的时候包装对象
If null -> JSONNull.NULLIf it is an array or collection, wrap it in a JSONArray. |
protected static Writer |
writeValue(Writer writer,
Object value,
int indentFactor,
int indent)
写入值到Writer
|
public static JSONObject createObj()
public static JSONArray createArray()
public static JSONObject parseObj(String jsonStr)
jsonStr - JSON字符串public static JSONArray parseArray(String jsonStr)
jsonStr - JSON字符串public static JSON parse(Object obj)
obj - 对象public static String toJsonStr(JSON json, int indentFactor)
json - JSONindentFactor - 每一级别的缩进public static String toJsonPrettyStr(Object obj)
obj - Bean对象public static <T> T toBean(JSONObject json, Class<T> beanClass)
json - JSONObjectbeanClass - 实体类对象public static String quote(String string)
string - A Stringpublic static Writer quote(String string, Writer writer) throws IOException
string - A Stringwriter - WriterIOExceptionpublic static Object wrap(Object object)
null -> JSONNull.NULLobject - The object to wrapprotected static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException
writer - Writervalue - 值indentFactor - indent - 缩进空格数JSONExceptionIOExceptionprotected static final void indent(Writer writer, int indent) throws IOException
writer - indent - IOExceptionprotected static String numberToString(Number number) throws JSONException
number - A NumberJSONException - If n is a non-finite number.protected static void testValidity(Object obj) throws JSONException
obj - 被检查的对象JSONException - If o is a non-finite number.protected static String valueToString(Object value) throws JSONException
Warning: This method assumes that the data structure is acyclical.
value - The value to be serialized.{ (left brace) and ending with } (right
brace).JSONException - If the value is or contains an invalid number.Copyright © 2016. All rights reserved.