import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
String content = inBankOdd.getContent().replace(""",""");
if(!content.equals("") && content != null){
JSONArray jsonArray = JSONArray.fromObject(content);
if(jsonArray.size()>0){
int num = 0 ;
double sumI = 0 ;
double sumP = 0 ;
for(int i=0;i<jsonArray.size();i++){
JSONObject object = jsonArray.getJSONObject(i); // 遍历 jsonarray 数组,把每一个对象转成 json 对象
String id = object.getString("id");
String inDis = object.getString("inDis");
String number = object.getString("number");
String price = object.getString("price");
String pricing = "0";
String practical = "0";
if(!price.isEmpty() && !number.isEmpty()){
pricing = new BigDecimal(number).multiply(new BigDecimal(price)).toString(); //单价乘数量 码洋
sumI = new BigDecimal(sumI).add(new BigDecimal(pricing)).doubleValue(); //码洋累加
}
if(!inDis.isEmpty() && !pricing.equals("0")){
practical = new BigDecimal(pricing).multiply(new BigDecimal(inDis)).toString(); //入库折扣乘码洋 实洋
sumP = new BigDecimal(sumP).add(new BigDecimal(practical)).doubleValue(); //实洋累加
} else {
practical = pricing ;
}
// String teachingMaterialNumber = teachingMaterial.getNumber().trim();
// if(teachingMaterialNumber != null && teachingMaterialNumber.length() != 0) {
// if(!number.isEmpty()){
// teachingMaterial.setNumber(String.valueOf((Integer.valueOf(number)+Integer.valueOf(teachingMaterial.getNumber()))));
// num += Integer.valueOf(number); //数量累加
// }
// } else {
// teachingMaterial.setNumber(number);
// }
}
inBankOdd.setContent(content);
inBankOdd.setNumber(String.valueOf(num));
inBankOdd.setPricing(String.valueOf(sumI));
inBankOdd.setPractical(String.valueOf(sumP));
}
}
用josn 导入jar
jar地址下载百度云:
链接:https://pan.baidu.com/s/1DqSzDeZ6uMAi8Iov-16sfQ
提取码:dy0k
复制这段内容后打开百度网盘手机App,操作更方便哦