Fastjson工具类

Fastjson 转换map,json等封装

/**

  • Fastjson工具类

  • Create by MR.Z on 2019/6/11
    /
    public class FastJsonUtil {
    /
    *

    • json转map
      */
      public static HashMap<String, String> json2Map(String json) {
      return JSON.parseObject(json, new HashMap<String, String>().getClass());
      }

    /**

    • map转json
      */
      public static String map2Json(Map<String, String> map) {
      String jsonStr = JSON.toJSONString(map);
      return jsonStr;
      }

    /**

    • json转对象
      */
      public static T json2Bean(String json, Class cls) {
      T t = null;
      try {
      t = JSON.parseObject(json, cls);
      } catch (Exception e) {
      e.printStackTrace();
      }
      return t;
      }

    /**

    • 对象转json
      */
      public static String bean2Json(Object obj) {
      return JSON.toJSONString(obj);
      }

    /**

    • json转List
      */
      public static List json2List(String json, Class cls) {
      List list = null;
      try {
      list = JSON.parseArray(json, cls);
      } catch (Exception e) {
      e.printStackTrace();
      }
      return list;
      }

    /**

    • json转ArrayList
      */
      public static ArrayList json2ArrayList(String json, Class cls) {
      ArrayList list = null;
      try {
      list = (ArrayList) JSON.parseArray(json, cls);
      } catch (Exception e) {
      e.printStackTrace();
      }
      return list;
      }

    /**

    • List转json
      */
      public static String list2Json(Object obj) {
      return JSONArray.toJSONString(obj, true);
      }

    /**

    • json转List
      */
      public static JSONArray json2List(String jsonStr) {
      return JSON.parseArray(jsonStr);
      }
      }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值