• java基础 -- json多层转换成对象


     

    "DATA" : [ {  
        "infoSource" : "IN",  
        "actOrderId" : 110718608,  
        "orderAppId" : "3200130001",  
        "orderAppCustomCategory" : null,  
        "channelLevel1" : 0,  
        "channelLevel2" : 0,  
        "channelLevel3" : 0,  
        "channelLevel4" : null,  
        "orderStatus" : 2,  
        "orderStatusDesc" : "已支付(待发货) ",  
        "payStatus" : 2,  
        "refundStatus" : 0,  
        "expressStatus" : 2,  
        "clossStatus" : 0,  
        "createTime" : "20151028101923",  
        "payTime" : "20151028102000",  
        "userId" : 177383800,  
        "andUserId" : null,  
        "showUrl" : null,  
        "shopId" : "11224193",  
        "shopName" : "避风塘",  
        "hasRefund" : 0,  
        "payOnDelivery" : 0,  
        "goodsInfos" : [ {  
          "goodsId" : 78259824,  
          "goodsName" : "食堂活动-自提商品",  
          "goodsImage" : "p_1911291824.jpg",  
          "price" : 1,  
          "count" : 3,  
          "goodsDetail" : null,  
          "goodsDesc" : null,  
          "isVirtual" : 0,  
          "payCount" : 3,  
          "goodsVersion" : "40170570"  
        } ],  
        "expressInfos" : [ {  
          "expressCompanyId" : 10000,  
          "expressNo" : null,  
          "receiverName" : null,  
          "address" : null,  
          "phoneNumber" : null,  
          "receiveTime" : "20151028103413",  
          "expressCost" : 0,  
          "status" : 2  
        } ],  
    json
    / JSON转换    
            JSONObject jsonObj = JSONObject.fromObject(goodsJson);    
            Map<String, Class> classMap = new HashMap<String, Class>();    
            classMap.put("DATA", DataInfoDto.class);    
            classMap.put("goodsInfos", GoodsInfoDto.class);      
            classMap.put("expressInfos", ExpressInfoDto.class);      
            // 将JSON转换成DeliveryInfoDto      
            DeliveryInfoDto delivery = (DeliveryInfoDto) JSONObject.toBean(jsonObj,      
            DeliveryInfoDto.class, classMap);    
    Test
    package com.justinmobile.lticket.domain.dto;  
      
    import java.io.Serializable;  
    import java.util.List;  
      
    /**  
     * 返回提货订单信息  
     * @author cm  
     */  
    @SuppressWarnings("serial")  
    public class DeliveryInfoDto implements Serializable  
    {  
        public String TOTALROW;  
        public List<DataInfoDto> DATA;  
          
        public DeliveryInfoDto(){  
            super();  
        }  
      
        public String getTOTALROW()  
        {  
            return TOTALROW;  
        }  
      
        public void setTOTALROW(String tOTALROW)  
        {  
            TOTALROW = tOTALROW;  
        }  
      
        public List<DataInfoDto> getDATA()  
        {  
            return DATA;  
        }  
      
        public void setDATA(List<DataInfoDto> dATA)  
        {  
            DATA = dATA;  
        }  
          
    }  
    DeliveryInfoDto
    package com.justinmobile.lticket.domain.dto;  
      
    import java.io.Serializable;  
    import java.util.List;  
      
    /** 
     * 返回提货订单信息 
     * @author cm 
     */  
    @SuppressWarnings("serial")  
    public class DataInfoDto implements Serializable  
    {  
        public String infoSource;  
        public Long actOrderId;  
        public String orderAppId;  
        public String orderAppCustomCategory;  
        public int channelLevel1;  
        public int channelLevel2;  
        public int channelLevel3;  
        public String channelLevel4;  
        public int orderStatus;  
        public String orderStatusDesc;  
        public int payStatus;  
        public int refundStatus;  
        public int expressStatus;  
        public int clossStatus;  
        public String createTime;  
        public String payTime;  
        public Long userId;  
        public String andUserId;  
        public String showUrl;    
        public String shopId;  
        public String shopName;  
        public int hasRefund;  
        public int payOnDelivery;  
        public List<GoodsInfoDto> goodsInfos;  
        public List<ExpressInfoDto> expressInfos;  
        public int totalPay;  
        public String refundUrl;  
          
        public DataInfoDto(){  
            super();  
        }  
        public String getInfoSource()  
        {  
            return infoSource;  
        }  
        public void setInfoSource(String infoSource)  
        {  
            this.infoSource = infoSource;  
        }  
        public Long getActOrderId()  
        {  
            return actOrderId;  
        }  
        public void setActOrderId(Long actOrderId)  
        {  
            this.actOrderId = actOrderId;  
        }  
        public String getOrderAppId()  
        {  
            return orderAppId;  
        }  
        public void setOrderAppId(String orderAppId)  
        {  
            this.orderAppId = orderAppId;  
        }  
        public String getOrderAppCustomCategory()  
        {  
            return orderAppCustomCategory;  
        }  
        public void setOrderAppCustomCategory(String orderAppCustomCategory)  
        {  
            this.orderAppCustomCategory = orderAppCustomCategory;  
        }  
        public int getChannelLevel1()  
        {  
            return channelLevel1;  
        }  
        public void setChannelLevel1(int channelLevel1)  
        {  
            this.channelLevel1 = channelLevel1;  
        }  
        public int getChannelLevel2()  
        {  
            return channelLevel2;  
        }  
        public void setChannelLevel2(int channelLevel2)  
        {  
            this.channelLevel2 = channelLevel2;  
        }  
        public int getChannelLevel3()  
        {  
            return channelLevel3;  
        }  
        public void setChannelLevel3(int channelLevel3)  
        {  
            this.channelLevel3 = channelLevel3;  
        }  
        public String getChannelLevel4()  
        {  
            return channelLevel4;  
        }  
        public void setChannelLevel4(String channelLevel4)  
        {  
            this.channelLevel4 = channelLevel4;  
        }  
        public int getOrderStatus()  
        {  
            return orderStatus;  
        }  
        public void setOrderStatus(int orderStatus)  
        {  
            this.orderStatus = orderStatus;  
        }  
        public String getOrderStatusDesc()  
        {  
            return orderStatusDesc;  
        }  
        public void setOrderStatusDesc(String orderStatusDesc)  
        {  
            this.orderStatusDesc = orderStatusDesc;  
        }  
        public int getPayStatus()  
        {  
            return payStatus;  
        }  
        public void setPayStatus(int payStatus)  
        {  
            this.payStatus = payStatus;  
        }  
        public int getRefundStatus()  
        {  
            return refundStatus;  
        }  
        public void setRefundStatus(int refundStatus)  
        {  
            this.refundStatus = refundStatus;  
        }  
        public int getExpressStatus()  
        {  
            return expressStatus;  
        }  
        public void setExpressStatus(int expressStatus)  
        {  
            this.expressStatus = expressStatus;  
        }  
        public int getClossStatus()  
        {  
            return clossStatus;  
        }  
        public void setClossStatus(int clossStatus)  
        {  
            this.clossStatus = clossStatus;  
        }  
        public String getCreateTime()  
        {  
            return createTime;  
        }  
        public void setCreateTime(String createTime)  
        {  
            this.createTime = createTime;  
        }  
        public String getPayTime()  
        {  
            return payTime;  
        }  
        public void setPayTime(String payTime)  
        {  
            this.payTime = payTime;  
        }  
        public Long getUserId()  
        {  
            return userId;  
        }  
        public void setUserId(Long userId)  
        {  
            this.userId = userId;  
        }  
        public String getAndUserId()  
        {  
            return andUserId;  
        }  
        public void setAndUserId(String andUserId)  
        {  
            this.andUserId = andUserId;  
        }  
        public String getShowUrl()  
        {  
            return showUrl;  
        }  
        public void setShowUrl(String showUrl)  
        {  
            this.showUrl = showUrl;  
        }  
        public String getShopId()  
        {  
            return shopId;  
        }  
        public void setShopId(String shopId)  
        {  
            this.shopId = shopId;  
        }  
        public String getShopName()  
        {  
            return shopName;  
        }  
        public void setShopName(String shopName)  
        {  
            this.shopName = shopName;  
        }  
        public int getHasRefund()  
        {  
            return hasRefund;  
        }  
        public void setHasRefund(int hasRefund)  
        {  
            this.hasRefund = hasRefund;  
        }  
        public int getPayOnDelivery()  
        {  
            return payOnDelivery;  
        }  
        public void setPayOnDelivery(int payOnDelivery)  
        {  
            this.payOnDelivery = payOnDelivery;  
        }  
        public List<GoodsInfoDto> getGoodsInfos()  
        {  
            return goodsInfos;  
        }  
        public void setGoodsInfos(List<GoodsInfoDto> goodsInfos)  
        {  
            this.goodsInfos = goodsInfos;  
        }  
        public List<ExpressInfoDto> getExpressInfos()  
        {  
            return expressInfos;  
        }  
        public void setExpressInfos(List<ExpressInfoDto> expressInfos)  
        {  
            this.expressInfos = expressInfos;  
        }  
        public int getTotalPay()  
        {  
            return totalPay;  
        }  
        public void setTotalPay(int totalPay)  
        {  
            this.totalPay = totalPay;  
        }  
        public String getRefundUrl()  
        {  
            return refundUrl;  
        }  
        public void setRefundUrl(String refundUrl)  
        {  
            this.refundUrl = refundUrl;  
        }  
      
    }  
    DataInfoDto
    package com.justinmobile.lticket.domain.dto;  
      
    import java.io.Serializable;  
    import java.math.BigDecimal;  
      
    /**  
     * 商品信息DTO  
     * @author cm  
     *  
     */  
    @SuppressWarnings("serial")  
    public class GoodsInfoDto implements Serializable  
    {  
        public Long goodsId;  
        public String goodsName;  
        public String goodsImage;  
        public BigDecimal price;  
        public int count;  
        public String goodsDetail;  
        public String goodsDesc;  
        public int isVirtual;  
        public int payCount;  
        public String goodsVersion;  
          
        public GoodsInfoDto(){  
            super();  
        }  
        public Long getGoodsId()  
        {  
            return goodsId;  
        }  
        public void setGoodsId(Long goodsId)  
        {  
            this.goodsId = goodsId;  
        }  
        public String getGoodsName()  
        {  
            return goodsName;  
        }  
        public void setGoodsName(String goodsName)  
        {  
            this.goodsName = goodsName;  
        }  
        public String getGoodsImage()  
        {  
            return goodsImage;  
        }  
        public void setGoodsImage(String goodsImage)  
        {  
            this.goodsImage = goodsImage;  
        }  
        public BigDecimal getPrice()  
        {  
            return price;  
        }  
        public void setPrice(BigDecimal price)  
        {  
            this.price = price;  
        }  
        public int getCount()  
        {  
            return count;  
        }  
        public void setCount(int count)  
        {  
            this.count = count;  
        }  
        public String getGoodsDetail()  
        {  
            return goodsDetail;  
        }  
        public void setGoodsDetail(String goodsDetail)  
        {  
            this.goodsDetail = goodsDetail;  
        }  
        public String getGoodsDesc()  
        {  
            return goodsDesc;  
        }  
        public void setGoodsDesc(String goodsDesc)  
        {  
            this.goodsDesc = goodsDesc;  
        }  
        public int getIsVirtual()  
        {  
            return isVirtual;  
        }  
        public void setIsVirtual(int isVirtual)  
        {  
            this.isVirtual = isVirtual;  
        }  
        public int getPayCount()  
        {  
            return payCount;  
        }  
        public void setPayCount(int payCount)  
        {  
            this.payCount = payCount;  
        }  
        public String getGoodsVersion()  
        {  
            return goodsVersion;  
        }  
        public void setGoodsVersion(String goodsVersion)  
        {  
            this.goodsVersion = goodsVersion;  
        }  
      
    }  
    GoodsInfoDto
    package com.justinmobile.lticket.domain.dto;  
      
    import java.io.Serializable;  
      
    /**  
     * 物流信息DTO  
     * @author cm  
     *  
     */  
    @SuppressWarnings("serial")  
    public class ExpressInfoDto implements Serializable  
    {  
        public Long expressCompanyId;  
        public String expressNo;  
        public String receiverName;  
        public String address;  
        public String phoneNumber;  
        public String receiveTime;  
        public int expressCost;  
        public int status;  
          
        public ExpressInfoDto(){  
            super();  
        }  
        public Long getExpressCompanyId()  
        {  
            return expressCompanyId;  
        }  
        public void setExpressCompanyId(Long expressCompanyId)  
        {  
            this.expressCompanyId = expressCompanyId;  
        }  
        public String getExpressNo()  
        {  
            return expressNo;  
        }  
        public void setExpressNo(String expressNo)  
        {  
            this.expressNo = expressNo;  
        }  
        public String getReceiverName()  
        {  
            return receiverName;  
        }  
        public void setReceiverName(String receiverName)  
        {  
            this.receiverName = receiverName;  
        }  
        public String getPhoneNumber()  
        {  
            return phoneNumber;  
        }  
        public void setPhoneNumber(String phoneNumber)  
        {  
            this.phoneNumber = phoneNumber;  
        }  
        public String getReceiveTime()  
        {  
            return receiveTime;  
        }  
        public void setReceiveTime(String receiveTime)  
        {  
            this.receiveTime = receiveTime;  
        }  
        public int getExpressCost()  
        {  
            return expressCost;  
        }  
        public void setExpressCost(int expressCost)  
        {  
            this.expressCost = expressCost;  
        }  
        public int getStatus()  
        {  
            return status;  
        }  
        public void setStatus(int status)  
        {  
            this.status = status;  
        }  
        public String getAddress()  
        {  
            return address;  
        }  
        public void setAddress(String address)  
        {  
            this.address = address;  
        }  
        
          
    }  
    ExpressInfoDto
  • 相关阅读:
    tensorflow 计算图模型的保存和恢复
    Python 小项目
    一些Python代码
    Anaconda 创建的新环境的位置, 解决pycharm中不能访问numpy的问题, conda命令 、设置镜像源、解决jupyter启动新环境kernel问题
    gdb调试程序
    一个完整的Makefile文件举例
    机器学习 Coursera Note
    2018年第九届蓝桥杯 第九题:全球变暖(满分23分)
    2018年第九届蓝桥杯 第八题:日志统计(满分21分)
    2018年第九届蓝桥杯 第七题:螺旋折线(满分19分)
  • 原文地址:https://www.cnblogs.com/ou-pc/p/7341632.html
Copyright © 2020-2023  润新知