public class JsonUtil extends Object
例如:
{ "array": [ 1, 2, 3 ], "type": true, "null": null, "number": 123, "object": { "a": "b", "c": "d", "e":1 }, "key": "welcome to CodeFormat.CN" }
Boolean type = JsonUtil.getBool(json,"type"); //type == true
int e = JsonUtil.getInt(json,"object.e") // e == 1
BigInteger n = JsonUtil.getBigInteger("number") // n == 123
String[] array = JsonUtil.get(json,"array",String[].class) //array == ["1","2","3"]
int[] array = JsonUtil.get(json,"array",int[].class) //array == [1,2,3]
Map map = JsonUtil.get(json,"object",Map.class) //map == {"a":"b","c":"d","e":1}
int x = JsonUtil.getInt(json,"array[1]"); // x == 2
String key = JsonUtil.getString(json,"key"); // key == "welcome to CodeFormat.CN"
| 构造器和说明 |
|---|
JsonUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static <T> T |
get(Object jsonObjectOrArray,
String key,
Class<T> clazz) |
static <T> T |
get(Object jsonObjectOrArray,
String key,
TypeDef<?> typeDef) |
static <T> T |
get(String json,
String key,
Class<T> clazz) |
static <T> T |
get(String json,
String key,
TypeDef<?> typeDef) |
static BigDecimal |
getBigDecimal(Object jsonObjectOrArray,
String key) |
static BigDecimal |
getBigDecimal(Object jsonObjectOrArray,
String key,
BigDecimal defaultValue) |
static BigDecimal |
getBigDecimal(String json,
String key) |
static BigDecimal |
getBigDecimal(String json,
String key,
BigDecimal defaultValue) |
static BigInteger |
getBigInteger(Object jsonObjectOrArray,
String key) |
static BigInteger |
getBigInteger(Object jsonObjectOrArray,
String key,
BigInteger defaultValue) |
static BigInteger |
getBigInteger(String json,
String key) |
static BigInteger |
getBigInteger(String json,
String key,
BigInteger defaultValue) |
static Boolean |
getBool(Object jsonObjectOrArray,
String key) |
static boolean |
getBool(Object jsonObjectOrArray,
String key,
boolean defaultValue) |
static Boolean |
getBool(String json,
String key) |
static boolean |
getBool(String json,
String key,
boolean defaultValue) |
static Date |
getDate(Object jsonObjectOrArray,
String key) |
static Date |
getDate(Object jsonObjectOrArray,
String key,
Date defaultValue) |
static Date |
getDate(String json,
String key) |
static Date |
getDate(String json,
String key,
Date defaultValue) |
static Double |
getDouble(Object jsonObjectOrArray,
String key) |
static double |
getDouble(Object jsonObjectOrArray,
String key,
double defaultValue) |
static Double |
getDouble(String json,
String key) |
static double |
getDouble(String json,
String key,
double defaultValue) |
static Float |
getFloat(Object jsonObjectOrArray,
String key) |
static float |
getFloat(Object jsonObjectOrArray,
String key,
float defaultValue) |
static Float |
getFloat(String json,
String key) |
static float |
getFloat(String json,
String key,
float defaultValue) |
static Integer |
getInt(Object jsonObjectOrArray,
String key) |
static int |
getInt(Object jsonObjectOrArray,
String key,
int defaultValue) |
static Integer |
getInt(String json,
String key) |
static int |
getInt(String json,
String key,
int defaultValue) |
static com.alibaba.fastjson.JSONArray |
getJSONArray(Object jsonObjectOrArray,
String key) |
static com.alibaba.fastjson.JSONArray |
getJSONArray(String json,
String key) |
static com.alibaba.fastjson.JSONObject |
getJSONObject(Object jsonObjectOrArray,
String key) |
static com.alibaba.fastjson.JSONObject |
getJSONObject(String json,
String key) |
static Object |
getJsonObjectOrArray(String json) |
static <T> List<T> |
getList(Object jsonObjectOrArray,
String key,
Class<T> clazz) |
static <T> List<T> |
getList(String json,
String key,
Class<T> clazz) |
static Long |
getLong(Object jsonObjectOrArray,
String key) |
static long |
getLong(Object jsonObjectOrArray,
String key,
long defaultValue) |
static Long |
getLong(String json,
String key) |
static long |
getLong(String json,
String key,
long defaultValue) |
static <T> Set<T> |
getSet(Object jsonObjectOrArray,
String key,
Class<T> clazz) |
static <T> Set<T> |
getSet(String json,
String key,
Class<T> clazz) |
static String |
getString(Object jsonObjectOrArray,
String key) |
static String |
getString(Object jsonObjectOrArray,
String key,
String defaultValue) |
static String |
getString(String json,
String key) |
static String |
getString(String json,
String key,
String defaultValue) |
public JsonUtil()
public static BigInteger getBigInteger(String json, String key)
public static BigInteger getBigInteger(Object jsonObjectOrArray, String key)
public static BigInteger getBigInteger(String json, String key, BigInteger defaultValue)
public static BigInteger getBigInteger(Object jsonObjectOrArray, String key, BigInteger defaultValue)
public static BigDecimal getBigDecimal(String json, String key)
public static BigDecimal getBigDecimal(Object jsonObjectOrArray, String key)
public static BigDecimal getBigDecimal(String json, String key, BigDecimal defaultValue)
public static BigDecimal getBigDecimal(Object jsonObjectOrArray, String key, BigDecimal defaultValue)
public static com.alibaba.fastjson.JSONObject getJSONObject(String json, String key)
public static com.alibaba.fastjson.JSONObject getJSONObject(Object jsonObjectOrArray, String key)
public static com.alibaba.fastjson.JSONArray getJSONArray(String json, String key)
public static com.alibaba.fastjson.JSONArray getJSONArray(Object jsonObjectOrArray, String key)
public static Object getJsonObjectOrArray(String json)
Copyright © 2024. All rights reserved.