Json转化

    public static PromoteActivityExt getExtByActivityDO(ActivityDO activityDO){
        if(null==activityDO){
            return null;
        }
        PromoteActivityExt activityExt = JSON.parseObject(activityDO.getFeature(), PromoteActivityExt.class);
        return activityExt;
    }

 

2、转列表:

  List<ProjectRestDTO> list = JSONObject.parseArray(getlowestPriceStr(), ProjectRestDTO.class);
        System.out.println(list.toString());

 

 

3、HashMap: json 转HashMap

 String operationParam = detailDO.getOperationParam();
                HashMap<String,String> hashMap = JSON.parseObject(operationParam, HashMap.class);
                String discountValue = hashMap.get(OperationParamEnum.DISCOUNT_VALUE.getKey());
                String brokerageRate = hashMap.get(OperationParamEnum.BROKERAGE_RATE.getKey());
                channelInfo.setDiscount(Double.valueOf(discountValue));
                channelInfo.setBrokerageRate(Integer.valueOf(brokerageRate));
        if (channelDO.getExtInfos() != null) {
                Map<String, Object> extInfoMap = new HashMap<>();
                JSONObject jsonObject = JSONObject.parseObject(channelDO.getExtInfos());
                if (jsonObject != null) {
                    jsonObject.forEach((k, v) -> {
                        extInfoMap.put(k, v);
                    });
                    ptnrChannelDTO.setExtInfo(extInfoMap);
                }
            }

 

 

HashMap转json转化:

 Map paramMap = new HashMap();
            paramMap.put(OperationParamEnum.DISCOUNT_VALUE.getKey(),String.valueOf(channelInfo.getDiscount()));
            paramMap.put(OperationParamEnum.BROKERAGE_RATE.getKey(),String.valueOf(channelInfo.getBrokerageRate()));
            activityDetailDO.setOperationParam(JSON.toJSONString(paramMap));

 

posted @ 2020-03-18 11:40  aspirant  阅读(275)  评论(0编辑  收藏  举报