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));
本文来自博客园,作者:aspirant,转载请注明原文链接:https://www.cnblogs.com/aspirant/p/12516389.html