取json对象里面的数组集合

    JSONObject json1 = JSON.parseObject(temp.getContent());
            JSONArray decLists = json1.getJSONArray("decLists");
            String tariff = "";
            String addedTax = "";
            for(int i = 0; i < decLists.size(); i++){
                JSONObject json = JSON.parseObject(decLists.getString(i));
                if(json.containsKey("tariff")){
                    String tariff1 = json.get("tariff").toString(); 
                    if("".equals(tariff1)){
                        tariff1="0";
                    }
                    double tariffnew = Double.parseDouble(tariff1);
                    if("".equals(tariff)){
                        tariff = "0";
                    }
                    double tariffold = Double.parseDouble(tariff);
                    double sum = tariffnew+tariffold;
                    tariff = String.valueOf(sum);
                }
                if(json.containsKey("addedTax")){ 
                    String addedTax1 = json.get("addedTax").toString(); 
                    if("".equals(addedTax1)){
                        addedTax1="0";
                    }
                    double addedTaxnew = Double.parseDouble(addedTax1);
                    if("".equals(addedTax)){
                        addedTax = "0";
                    }
                    double addedTaxold = Double.parseDouble(addedTax);
                    double sum = addedTaxnew+addedTaxold;
                    addedTax = String.valueOf(sum);

                }
            }

 

posted @ 2020-04-08 16:56  薛柏梁  阅读(10747)  评论(0编辑  收藏  举报