【问题标题】:Gson can not parse nested string objectGson 无法解析嵌套的字符串对象
【发布时间】:2016-10-01 12:35:57
【问题描述】:
如何解析嵌套对象
[{
"id": 100500,
"products": "[{\"id\":45,\"title\":\"All Product\"]"
}]
模型类
public class Store {
public long id;
public List<Product> products;
}
【问题讨论】:
标签:
java
android
arrays
json
gson
【解决方案1】:
你好,把 Gson 改成
{
"Id": "100500",
"products": [
{
"id": 1,
"title": "title 1"
},
{
"id": 2,
"title": "title 2"
},
{
"id": 3,
"title": "title 3"
}
]
}
【解决方案2】:
不会解析
public class Store {
public long id;
public List<Product> products;
}
Gson mGson= new Gson();
storeList=mGson.fromJson(json, Store.class);
storeList.getStores().get(0).getProducts().get(1);