Gson解析

 

1.定义对象,名字要与json对象一致

/**
 * totalCount : 28
 * currentPage : 1
 * totalPage : 28
 * pageSize : 1
 * list : [{"id":1,"name":"联想(Lenovo)拯救者14.0英寸游戏本(i7-4720HQ 4G 1T硬盘 GTX960M 2G独显 FHD IPS屏 背光键盘)黑","imgUrl":"http://7mno4h.com2.z0.glb.qiniucdn.com/s_recommend_55c1e8f7N4b99de71.jpg","description":null,"price":5979,"sale":8654}]
 */

private int totalCount;
private int currentPage;
private int totalPage;
private int pageSize;
/**
 * id : 1
 * name : 联想(Lenovo)拯救者14.0英寸游戏本(i7-4720HQ 4G 1T硬盘 GTX960M 2G独显 FHD IPS屏 背光键盘)黑
 * imgUrl : http://7mno4h.com2.z0.glb.qiniucdn.com/s_recommend_55c1e8f7N4b99de71.jpg
 * description : null
 * price : 5979.0
 * sale : 8654
 */

private List<ListBean> list;

public int getTotalCount() {
    return totalCount;
}

public void setTotalCount(int totalCount) {
    this.totalCount = totalCount;
}

public int getCurrentPage() {
    return currentPage;
}

public void setCurrentPage(int currentPage) {
    this.currentPage = currentPage;
}

public int getTotalPage() {
    return totalPage;
}

public void setTotalPage(int totalPage) {
    this.totalPage = totalPage;
}

public int getPageSize() {
    return pageSize;
}

public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
}

public List<ListBean> getList() {
    return list;
}

public void setList(List<ListBean> list) {
    this.list = list;
}

public static class ListBean {
    private int id;
    private String name;
    private String imgUrl;
    private Object description;
    private double price;
    private int sale;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public Object getDescription() {
        return description;
    }

    public void setDescription(Object description) {
        this.description = description;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getSale() {
        return sale;
    }

    public void setSale(int sale) {
        this.sale = sale;
    }
}

1.解析

//GSON直接解析成对象
ShopBean resultBean = new Gson().fromJson(strByJson,ShopBean.class);
//对象中拿到集合
List<ShopBean.ListBean> userBeanList = resultBean.getList();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值