Class JsonKit

java.lang.Object
org.miaixz.bus.extra.json.JsonKit

public class JsonKit extends Object
json工具类,通过SPI自动识别
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • JsonKit

      public JsonKit()
  • Method Details

    • getProvider

      public static JsonProvider getProvider()
      获得全局单例的json映射器
      Returns:
      全局单例的json映射器
    • toJsonString

      public static String toJsonString(Object object)
      解析对象为Json字符串
      Parameters:
      object - 要转换的对象
      Returns:
      返回对象的json字符串
    • toJsonString

      public static String toJsonString(Object object, String format)
      解析对象为Json字符串
      Parameters:
      object - 要转换的对象
      format - 日期格式,如"yyyy年MM月dd日 HH时mm分ss秒"
      Returns:
      返回对象的json字符串
    • toPojo

      public static <T> T toPojo(String json, Class<T> clazz)
      解析json字符串到指定类型的对象
      Type Parameters:
      T - 泛型参数类型
      Parameters:
      json - 要解析的json字符串
      clazz - 类对象class
      Returns:
      返回解析后的对象
    • toPojo

      public static <T> T toPojo(Map map, Class<T> clazz)
      从Map转换到对象
      Type Parameters:
      T - 泛型参数类型
      Parameters:
      map - Map对象
      clazz - 与Map可兼容的对象类型
      Returns:
      返回Map转换得到的对象
    • toList

      public static List toList(String json)
      解析json字符串到List
      Parameters:
      json - 要解析的json字符串
      Returns:
      返回List
    • toList

      public static <T> List<T> toList(String json, Type type)
      按指定的Type解析json字符串到List
      Type Parameters:
      T - 泛型参数类型
      Parameters:
      json - 要解析的json字符串
      type - Type
      Returns:
      返回List
    • toList

      public static <T> List<T> toList(String json, Class<T> clazz)
      按指定的Type解析json字符串到List
      Type Parameters:
      T - 泛型参数类型
      Parameters:
      json - 要解析的json字符串
      clazz - 类对象class
      Returns:
      返回List
    • toMap

      public static Map toMap(String json)
      解析json字符串到Map
      Parameters:
      json - 要解析的json字符串
      Returns:
      返回Map
    • toMap

      public static Map toMap(Object object)
      转换对象到Map
      Parameters:
      object - 与Map可兼容的对象
      Returns:
      返回Map对象
    • getValue

      public static <T> T getValue(String json, String field)
      获取json字符串指定属性值
      Type Parameters:
      T - 泛型参数类型
      Parameters:
      json - 要解析的json字符串
      field - 属性名称
      Returns:
      返回解析后的属性值
    • isJson

      public static boolean isJson(String json)
      判断是否为标准json
      Parameters:
      json - 字符串
      Returns:
      the true/false