类 Json

java.lang.Object
cn.datastacks.durian.Json

public final class Json extends Object
Json 工具类:Json 和 对象(数组)之间的相互转换。
作者:
yurun
  • 字段详细资料

    • INT_ARRAY

      public static final Type INT_ARRAY
      整数数组
    • LONG_ARRAY

      public static final Type LONG_ARRAY
      长整数数组
    • FLOAT_ARRAY

      public static final Type FLOAT_ARRAY
      单精度浮点数数组
    • DOUBLE_ARRAY

      public static final Type DOUBLE_ARRAY
      双精度浮点数数组
    • BOOLEAN_ARRAY

      public static final Type BOOLEAN_ARRAY
      布尔数组
    • STRING_ARRAY

      public static final Type STRING_ARRAY
      字符串数组
    • OBJECT_ARRAY

      public static final Type OBJECT_ARRAY
      对象数组
    • INT_LIST

      public static final Type INT_LIST
      整数列表
    • LONG_LIST

      public static final Type LONG_LIST
      长整数列表
    • FLOAT_LIST

      public static final Type FLOAT_LIST
      单精度浮点数列表
    • DOUBLE_LIST

      public static final Type DOUBLE_LIST
      双精度浮点数列表
    • BOOLEAN_LIST

      public static final Type BOOLEAN_LIST
      布尔列表
    • STRING_LIST

      public static final Type STRING_LIST
      字符串列表
    • OBJECT_LIST

      public static final Type OBJECT_LIST
      对象列表
    • INT_MAP

      public static final Type INT_MAP
      整数字典
    • LONG_MAP

      public static final Type LONG_MAP
      长整数字典
    • FLOAT_MAP

      public static final Type FLOAT_MAP
      单精度浮点数字典
    • DOUBLE_MAP

      public static final Type DOUBLE_MAP
      双精度浮点数字典
    • BOOLEAN_MAP

      public static final Type BOOLEAN_MAP
      布尔字典
    • STRING_MAP

      public static final Type STRING_MAP
      字符串字典
    • OBJECT_MAP

      public static final Type OBJECT_MAP
      对象字典
  • 方法详细资料

    • toJson

      public static String toJson(Object object)
      对象转换成 Json 字符串
      参数:
      object - 对象
      返回:
      Json 字符串
    • fromJson

      public static <T> T fromJson(String json, Class<T> clazz)
      Json 字符串转换成对象
      类型参数:
      T - 对象类型或方法返回值类型
      参数:
      json - Json 字符串
      clazz - 对象类
      返回:
      对象
    • fromJson

      public static <T> T fromJson(String json, Type type)
      Json 字符串转换成对象
      类型参数:
      T - 方法返回值类型
      参数:
      json - Json 字符串
      type - 对象类型
      返回:
      对象
    • parse

      public static com.google.gson.JsonElement parse(String json)
      Json 字符串解析成 Json 分析树
      参数:
      json - Json 字符串
      返回:
      Json 分析树
    • isJson

      public static boolean isJson(String json)
      检查字符串是否是 Json,包括:基本数据类型、对象、数组或 null
      参数:
      json - 字符串
      返回:
      如果字符串是 Json,返回 true;否则,返回 false
    • isJsonPrimitive

      public static boolean isJsonPrimitive(String json)
      检查字符串是否是 Json 基本数据类型
      参数:
      json - 字符串
      返回:
      如果字符串是 Json 基本数据类型,返回 true;否则,返回 false
    • isJsonObject

      public static boolean isJsonObject(String json)
      检查字符串是否是 Json 对象
      参数:
      json - 字符串
      返回:
      如果字符串是 Json 对象,返回 true;否则,返回 false
    • isJsonArray

      public static boolean isJsonArray(String json)
      检查字符串是否是 Json 数组
      参数:
      json - 字符串
      返回:
      如果字符串是 Json 数组,返回 true;否则,返回 false
    • isJsonNull

      public static boolean isJsonNull(String json)
      检查字符串是否是 Json null
      参数:
      json - 字符串
      返回:
      如果字符串是 Json null,返回 true;否则,返回 false