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); 是不行的

原文地址:https://www.cnblogs.com/SHMILYHP/p/5766084.html