皮卡丘踢球
2016-11-24 11:08
采纳率: 100%
浏览 2.1k
已采纳

json数组解析成对象问题

{"Products":[{"years":"2006","proCode":"BYQ","throughput":"1","unit":"2","yield":"3","unit2":"4","totalHour"
:"5"},{"years":"2006","proCode":"","throughput":"11","unit":"22","yield":"33","unit2":"44","totalHour"
:"55"}],"Material":[{"years":"2006","matCode":"BYQ","consump":"111","unit":"222"}],"EnerConsu":[{"years"
:"2006","energyCode":"BYQ","consump":"1111","unit":"2222","useMaterial":"3333","unit2":"4444"}]}

请大神帮解析这个json然后封装到对象.一共是三个对象

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • 天蓝风暖 2016-11-25 00:47
    已采纳

    import java.util.List;
    public class EntityInfo {

    private List<ProductsBean> Products;
    private List<MaterialBean> Material;
    private List<EnerConsuBean> EnerConsu;
    
    public List<ProductsBean> getProducts() {
        return Products;
    }
    
    public void setProducts(List<ProductsBean> Products) {
        this.Products = Products;
    }
    
    public List<MaterialBean> getMaterial() {
        return Material;
    }
    
    public void setMaterial(List<MaterialBean> Material) {
        this.Material = Material;
    }
    
    public List<EnerConsuBean> getEnerConsu() {
        return EnerConsu;
    }
    
    public void setEnerConsu(List<EnerConsuBean> EnerConsu) {
        this.EnerConsu = EnerConsu;
    }
    
    public static class ProductsBean {
        /**
         * years : 2006
         * proCode : BYQ
         * throughput : 1
         * unit : 2
         * yield : 3
         * unit2 : 4
         * totalHour : 5
         */
    
        private String years;
        private String proCode;
        private String throughput;
        private String unit;
        private String yield;
        private String unit2;
        private String totalHour;
    
        public String getYears() {
            return years;
        }
    
        public void setYears(String years) {
            this.years = years;
        }
    
        public String getProCode() {
            return proCode;
        }
    
        public void setProCode(String proCode) {
            this.proCode = proCode;
        }
    
        public String getThroughput() {
            return throughput;
        }
    
        public void setThroughput(String throughput) {
            this.throughput = throughput;
        }
    
        public String getUnit() {
            return unit;
        }
    
        public void setUnit(String unit) {
            this.unit = unit;
        }
    
        public String getYield() {
            return yield;
        }
    
        public void setYield(String yield) {
            this.yield = yield;
        }
    
        public String getUnit2() {
            return unit2;
        }
    
        public void setUnit2(String unit2) {
            this.unit2 = unit2;
        }
    
        public String getTotalHour() {
            return totalHour;
        }
    
        public void setTotalHour(String totalHour) {
            this.totalHour = totalHour;
        }
    }
    
    public static class MaterialBean {
        /**
         * years : 2006
         * matCode : BYQ
         * consump : 111
         * unit : 222
         */
    
        private String years;
        private String matCode;
        private String consump;
        private String unit;
    
        public String getYears() {
            return years;
        }
    
        public void setYears(String years) {
            this.years = years;
        }
    
        public String getMatCode() {
            return matCode;
        }
    
        public void setMatCode(String matCode) {
            this.matCode = matCode;
        }
    
        public String getConsump() {
            return consump;
        }
    
        public void setConsump(String consump) {
            this.consump = consump;
        }
    
        public String getUnit() {
            return unit;
        }
    
        public void setUnit(String unit) {
            this.unit = unit;
        }
    }
    
    public static class EnerConsuBean {
        /**
         * years : 2006
         * energyCode : BYQ
         * consump : 1111
         * unit : 2222
         * useMaterial : 3333
         * unit2 : 4444
         */
    
        private String years;
        private String energyCode;
        private String consump;
        private String unit;
        private String useMaterial;
        private String unit2;
    
        public String getYears() {
            return years;
        }
    
        public void setYears(String years) {
            this.years = years;
        }
    
        public String getEnergyCode() {
            return energyCode;
        }
    
        public void setEnergyCode(String energyCode) {
            this.energyCode = energyCode;
        }
    
        public String getConsump() {
            return consump;
        }
    
        public void setConsump(String consump) {
            this.consump = consump;
        }
    
        public String getUnit() {
            return unit;
        }
    
        public void setUnit(String unit) {
            this.unit = unit;
        }
    
        public String getUseMaterial() {
            return useMaterial;
        }
    
        public void setUseMaterial(String useMaterial) {
            this.useMaterial = useMaterial;
        }
    
        public String getUnit2() {
            return unit2;
        }
    
        public void setUnit2(String unit2) {
            this.unit2 = unit2;
        }
    }
    

    }

    
    
    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题