zoukankan      html  css  js  c++  java
  • 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); 是不行的

  • 相关阅读:
    美多商城项目(一)
    Linux安装Qt
    mysql之初体验
    Linux系统编程目录
    Linux 多线程
    进程间通信
    Linux进程
    Linux文件IO(简易)
    Linux常用基本操作
    重绘
  • 原文地址:https://www.cnblogs.com/SHMILYHP/p/5766084.html
Copyright © 2011-2022 走看看