码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-08-12 19:48:11      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:

//计算其他收费
            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); 是不行的

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

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!