字符串对象转换list实体类(字符串是单引号的json格式)例如{'name':'zs','age':'23'}
字符串里面携带特殊字符(}','{)需要替换下,同时在字符串前后拼接[ ]
String str ="["+ "{'createTime':'2021-10-1509:04:15','updateTime':'2021-10-1510:27:39','createBy':'null','updateBy':'null','remark':'null','id':'433d82db213e1d95edae954ec3ead26e','userId':'179','materialCode':'M041-HYSZFXDQ$backslash$ZH-200X300-GD-BXG-10','materialName':'环氧树脂富锌底漆$backslash$中灰','goodsModel':'200X300','goodsClassify':'M041','goodsLocation':'a-s-d','measuringUnit':'ST','number':'1111','freezeNum':'null','materialUnit':'1','texture':'不锈钢','specification':'GD','scoreSize':'10','userName':'武威','isdel':'1'}','{'createTime':'2021-10-1509:04:15','updateTime':'null','createBy':'null','updateBy':'null','remark':'null','id':'7002ccbe9032eada244fac6eb1b014d2','userId':'179','materialCode':'M081-HYSZFXDQ$backslash$ZH-200X300-GD-BXG-10','materialName':'环氧树脂富锌底漆$backslash$中灰','goodsModel':'200X300','goodsClassify':'M081','goodsLocation':'a-s-d','measuringUnit':'TO','number':'2222','freezeNum':'null','materialUnit':'1','texture':'不锈钢','specification':'GD','scoreSize':'10','userName':'武威','isdel':'1'}','{'createTime':'2021-10-1509:04:15','updateTime':'null','createBy':'null','updateBy':'null','remark':'null','id':'a472dce01a181f1b6219acf34d573d76','userId':'179','materialCode':'M061-JAZQXSJ$backslash$BXSJAZMQY-200X300-GD-BXG-10','materialName':'聚氨酯漆稀释剂$backslash$丙烯酸聚氨酯面漆用','goodsModel':'200X300','goodsClassify':'M061','goodsLocation':'a-s-d','measuringUnit':'M','number':'33333','freezeNum':'null','materialUnit':'1','texture':'不锈钢','specification':'GD','scoreSize':'10','userName':'武威','isdel':'1'}','{'createTime':'2021-10-1509:04:15','updateTime':'null','createBy':'null','updateBy':'null','remark':'null','id':'b806e33ce58fbb1943376224e2d1e738','userId':'179','materialCode':'M061-BXSZJAZMQ$backslash$YF-200X300-GD-BXG-10','materialName':'丙烯酸酯聚氨酯面漆$backslash$银粉','goodsModel':'200X300','goodsClassify':'M061','goodsLocation':'a-s-d','measuringUnit':'KG','number':'44444','freezeNum':'null','materialUnit':'1','texture':'不锈钢','specification':'GD','scoreSize':'10','userName':'武威','isdel':'1'}" + "]";
字符串替换后转JSONArray数组然后转对应list实体类,同时对特殊字符进行转译
String all = aa.replaceAll("}','\\{", "},{");
com.alibaba.fastjson.JSONArray jsonArray = JSON.parseArray(all);
List<MaterialInfoDTO> materialInfoDTOList = JSONObject.parseArray(jsonArray.toJSONString(), MaterialInfoDTO.class);
for (MaterialInfoDTO materialInfoDTO : materialInfoDTOList) {
if(StringUtils.isNotBlank(materialInfoDTO.getMaterialCode())){
String code = materialInfoDTO.getMaterialCode().replace("$backslash$", "\\");
String name = materialInfoDTO.getMaterialName().replace("$backslash$", "\\");
System.out.println( code + " ============ " +name);
}
}
double数据类型怎么加减乘除计算并比较大小和四舍五入
double b1 = 0.004;
double b2 = 0.004;
//先将double装换为 BigDecimal,加减后再转double
// 相加 :
double d1 = new BigDecimal(b1).add( new BigDecimal(b2)).doubleValue();
// 相减 :
double d2 = new BigDecimal(b1).subtract( new BigDecimal(b2)).doubleValue();
// 相乘 :
double d3 = new BigDecimal(b1).multiply( new BigDecimal(b2)).doubleValue();
// 相除 :
double d4 = new BigDecimal(b1).divide( new BigDecimal(b2)).doubleValue();
// 四舍五入保留2位小数:
double d5 = new BigDecimal(b1).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
//double比较大小 直接通过 >、 <、 >=、 <=、 ==等符合进行比较
if(b1 >= b2 ){
System.out.println(" >= " );
}