嗨,我的 json 是这样的,我使用 gson 转换为 Java,我创建了一个包含所有属性的顶级类和另一个具有列表的类。但是,即使数组大小正确,这些值也会打印为 null。我究竟做错了什么?
Gson json = new Gson();
ProductListResponse [] response = json.fromJson(str, ProductListResponse[].class);
public class ProductList {
public String code;
public String name;
public String description;
public Date lastUpdateDate;
public String lastUpdatedBy;
}
------------------------------------------------------------------------------------
public class ProductListResponse {
public ProductList plist;
}
-------------------------------------------------------------------------------------------
[
{
"product": {
"code": "RA",
"name": "Read About",
"description": "Read About"
}
},
{
"product": {
"code": "READ180",
"name": "Read180",
"description": "Read180"
}
},
{
"product": {
"code": "RLIB",
"name": "Read180 Library Catalog",
"description": "Read180 Library Catalog",
"last_udapte_date": "2010-12-07 00:00:00.0",
"last_updated_by": "fdixon00"
}
},
{
"product": {
"code": "EREADS",
"name": "Read180 eReads",
"description": "Read180 eReads"
}
},
{
"product": {
"code": "RSKILL",
"name": "Read180 rSkills",
"description": "Read180 rSkills",
"last_udapte_date": "2010-09-20 00:00:00.0",
"last_updated_by": "fdixon00"
}
},
{
"product": {
"code": "POOL",
"name": "Reference Asset Pool",
"description": "Reference Asset Pool"
}
},
{
"product": {
"code": "SU",
"name": "Scholastic U",
"description": "Scholastic U"
}
},
{
"product": {
"code": "TR8TS",
"name": "Six Traits of Writing",
"description": "Six Traits of Writing"
}
},
{
"product": {
"code": "TFX",
"name": "TrueFlix",
"description": "TrueFlix",
"last_udapte_date": "2012-08-20 10:47:46.0",
"last_updated_by": "wbyler00"
}
}
]