以下是来自Web服务的public class Product {
private int id,price,discount;
private String name,image,description,discount_type,discount_exp;
@SerializedName("products")
private List<Product> products;
public Product()
{
}
}
响应:
和Java类:
db.foo.find({"_id" : ObjectId("59b0303bfe409a21fccc9523")})
.map(function(u){
return u.Departments
.filter(p => p.Guid == "D5950FC8-91B1-48A3-8B6A-F3A72FAC9175")
}
)
响应为空
答案 0 :(得分:0)
问题是产品包含在JSON
响应的数据字段中。 Retrofit
不知道这一点,因此无法将响应反序列化为Product数组。
答案 1 :(得分:0)
你必须改变它会起作用
<h1>Image in src attribute</h1>
<img width="30" src="http://c.reapic1.com/camera.svg">
<h1>Image in content url</h1>
<div class="test-content">
<img>
</div>
<h1>Image in before content url</h1>
<div class="test-before-content">
<img>
</div>
<h1>Image in after content url</h1>
<div class="test-after-content">
<img>
</div>
<h1>Image as background</h1>
<div class="test-background">
<img>
</div>
答案 2 :(得分:0)
POJO
class
错误
试试这个
public class Products_Main
{
@SerializedName("current_page")
int current_page;
@SerializedName("data")
private List<Product> products;
public int getCurrent_page() {
return current_page;
}
public void setCurrent_page(int current_page) {
this.current_page = current_page;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
}
和
class Product {
@SerializedName("id")
private int id;
@SerializedName("price")
int price;
@SerializedName("discount")
int discount;
@SerializedName("name")
private String name;
@SerializedName("image")
private String image;
@SerializedName("description")
private String description;
@SerializedName("discount_type")
private String discount_type;
@SerializedName("discount_exp")
private String discount_exp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getDiscount() {
return discount;
}
public void setDiscount(int discount) {
this.discount = discount;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDiscount_type() {
return discount_type;
}
public void setDiscount_type(String discount_type) {
this.discount_type = discount_type;
}
public String getDiscount_exp() {
return discount_exp;
}
public void setDiscount_exp(String discount_exp) {
this.discount_exp = discount_exp;
}
}
答案 3 :(得分:0)
解析失败时会发生任何空数据。
这是您已经显示的回复的Java
public class ProductResponse {
ProductPage products;
}
public class ProductPage {
int current_page;
@SerializedName("data")
private List<Product> products;
}
public class Product {
private int id,price,discount;
private String name,image,description,discount_type,discount_exp;
public Product() { }
}
答案 4 :(得分:0)
你应该像那样使用它
=&gt;主API模型类
public class APIResult {
@SerializedName("products")
private ProductModelClass products;
public ProductModelClass getProducts() {
return products;
}
public void setProducts(ProductModelClass products) {
this.products = products;
}
}
=&gt;对于数据和当前页面模型类
public class ProductModelClass {
@SerializedName("current_page")
private int current_page;
@SerializedName("data")
private ArrayList<ProductDataModel> data;
public int getCurrent_page() {
return current_page;
}
public void setCurrent_page(int current_page) {
this.current_page = current_page;
}
public ArrayList<ProductDataModel> getData() {
return data;
}
public void setData(ArrayList<ProductDataModel> data) {
this.data = data;
}
}
=&gt;有关产品数据的详细信息
public class ProductDataModel {
@SerializedName("id")
private int id;
@SerializedName("name")
private String name;
@SerializedName("image")
private String image;
@SerializedName("description")
private String description;
@SerializedName("price")
private int price;
@SerializedName("discount")
private int discount;
@SerializedName("shop_id")
private int shop_id;
@SerializedName("discount_type")
private String discount_type;
@SerializedName("discount_exp")
private String discount_exp;
@SerializedName("discount_limit")
private String discount_limit;
@SerializedName("vote_id")
private String vote_id;
@SerializedName("video_id")
private String video_id;
@SerializedName("status")
private String status;
@SerializedName("created_at")
private String created_at;
@SerializedName("updated_at")
private String updated_at;
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 getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getDiscount() {
return discount;
}
public void setDiscount(int discount) {
this.discount = discount;
}
public int getShop_id() {
return shop_id;
}
public void setShop_id(int shop_id) {
this.shop_id = shop_id;
}
public String getDiscount_type() {
return discount_type;
}
public void setDiscount_type(String discount_type) {
this.discount_type = discount_type;
}
public String getDiscount_exp() {
return discount_exp;
}
public void setDiscount_exp(String discount_exp) {
this.discount_exp = discount_exp;
}
public String getDiscount_limit() {
return discount_limit;
}
public void setDiscount_limit(String discount_limit) {
this.discount_limit = discount_limit;
}
public String getVote_id() {
return vote_id;
}
public void setVote_id(String vote_id) {
this.vote_id = vote_id;
}
public String getVideo_id() {
return video_id;
}
public void setVideo_id(String video_id) {
this.video_id = video_id;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getCreated_at() {
return created_at;
}
public void setCreated_at(String created_at) {
this.created_at = created_at;
}
public String getUpdated_at() {
return updated_at;
}
public void setUpdated_at(String updated_at) {
this.updated_at = updated_at;
}
}