public class JSONUtil extends Object
| 构造器和说明 |
|---|
JSONUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected static void |
indent(Writer writer,
int indent)
缩进,使用空格符
|
protected static String |
numberToString(Number number)
Produce a string from a Number.
|
static JSONObject |
parse(String jsonStr)
JSON字符串转JSONObject对象
|
static JSONArray |
parseArray(String jsonStr)
JSON字符串转JSONArray
|
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(JSONArray jsonArray)
转为格式化后的JSON字符串
|
static String |
toJsonPrettyStr(JSONObject jsonObject)
转为格式化后的JSON字符串
|
static String |
toJsonStr(JSONArray jsonArray)
转为JSON字符串
|
static String |
toJsonStr(JSONObject jsonObject)
转为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 parse(String jsonStr)
jsonStr - JSON字符串public static JSONArray parseArray(String jsonStr)
jsonStr - JSON字符串public static String toJsonStr(JSONObject jsonObject)
jsonObject - JSONObjectpublic static String toJsonStr(JSONArray jsonArray)
jsonArray - JSONArraypublic static String toJsonPrettyStr(JSONObject jsonObject)
jsonObject - JSONObjectpublic static String toJsonPrettyStr(JSONArray jsonArray)
jsonArray - JSONArraypublic 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.