Gson无法解析嵌套的字符串对象

时间:2016-10-01 12:35:57

标签: java android arrays json gson

如何解析嵌套对象

 [{
       "id": 100500,
       "products": "[{\"id\":45,\"title\":\"All Product\"]"
    }]

模型类

public class Store {
      public  long id;
      public  List<Product> products;

}

2 个答案:

答案 0 :(得分:1)

不会解析

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);

答案 1 :(得分:1)

嗨,你把Gson改成

{
  "Id": "100500",
  "products": [

      {
        "id": 1,
        "title": "title 1"
      },
      {
         "id": 2,
         "title": "title 2"
      },
      {
        "id": 3,
          "title": "title 3"
      } 

  ]
}