1:手动在外面包一层 {"list":[]},用于符合Gson解析
2:json数据格式不对 foodName 后面的逗号 ,要去掉
json:{"list":[
{
"shopId":1,
"shopName":"蛋糕房",
"shopPicture":"http://10.113.104.89:8080/order/img/shop/shop1.png",
"foodList":[
{
"foodId":"1",
"foodName":"招牌丰收硕果12寸"
},
{
"foodId":"2",
"foodName":"玫瑰花创意蛋糕"
}
]
}
]
}
结果如下:
class ResultBean {
public ArrayList<Item> list = new ArrayList<Item>();
class Item {
public int shopId;
public String shopName;
public String shopPicture;
public ArrayList<FoodItem> foodList = new ArrayList<FoodItem>();
class FoodItem {
public String foodId;
public String foodName;
}
}
}
String json="{\"list\":[\n" +
"{\n" +
"\"shopId\":1,\n" +
"\"shopName\":\"蛋糕房\",\n" +
"\"shopPicture\":\"http://10.113.104.89:8080/order/img/shop/shop1.png\",\n" +
"\"foodList\":[\n" +
" { \n" +
" \"foodId\":\"1\",\n" +
" \"foodName\":\"招牌丰收硕果12寸\"\n" +
" },\n" +
" {\n" +
" \"foodId\":\"2\",\n" +
" \"foodName\":\"玫瑰花创意蛋糕\"\n" +
" } \n" +
" ]\n" +
"}\n" +
"]\n" +
"}";
ResultBean result= new Gson().fromJson(json,ResultBean.class);