GsonUtils.getGson().fromJson() 转泛型集合用法


//计算其他收费
            List<QiTaFree> qiTaFreeList = GsonUtils.getGson().fromJson(exhiMain.getQiTaFressJson(), new TypeToken<List<QiTaFree>>(){}.getType());
            exhiMain.setQiTaFrees(qiTaFreeList);//其他
            if(qiTaFreeList !=null && qiTaFreeList.size()>0){
                for(QiTaFree qiTaFree : qiTaFreeList){
                    if("1".equals(qiTaFree.getCalType())){//1表示以单位计算
                        otherCharges = (long) (otherCharges + qiTaFree.getPrice());
                    }else if("2".equals(qiTaFree.getCalType())){//表示以展位面积计算
                        otherCharges = otherCharges + Math.round(qiTaFree.getPrice() * zhanArea);
                    }
                    
                }
            }//计算其他收费end

当转集合泛型时候 请这样GsonUtils.getGson().fromJson(exhiMain.getQiTaFressJson(), new TypeToken<List<QiTaFree>>(){}.getType());

如果比如这样转List<String> fanList = GsonUtils.getGson().fromJson(exhiMain.getFanWei(), ArrayList.class); 是不行的


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM