我有一个Json字符串。我无法通过带有两个列表(类别和产品)的翻新进行onResponse。我怎么称呼,回叫?我应该用什么?通常不是列表,对吧?



{
"Categories": [{"name":"x products",
                "products":[{}{}{}]}
                {"name":"y products",
                "products":[{}{}{}]}
                {"name":"z products",
                "products":[{}{}{}]} ],
"CoverPageURL":"xx.png",
"Location": "Canada",
"adress":"opposite of hospital"
"ProductItems": [
          {"large":"xx"
            "mall":"tt"}
           {"large":"yy"
            "mall":"gg"}]
"Status": {
"ErrorCode": 0,
"Error": null,
"HasError": false
  }
   





通常我会那样做



Call<Merchant> call = ToolApi.getApi().GetMerchant(BaseService.TOKEN);
        call.enqueue(new Callback<Merchant>() {
            @Override
            public void onResponse(Response<Merchant> response, Retrofit retrofit) {
                if (response.body() == null) {
}else{

//I bought the bottoms from another class just For example
//normaly one list and its' items. but in that case i have two list on JSON
//start
   HomePageContent homePageContent = response.body();
                    Integer errorCode = homePageContent.getStatus().getErrorCode();

                    if (errorCode == 0) {
/// What i should write here
                        List<ItemHomePagecontent> items = homePageContent.getItems();
                        HeadRecyclerListHomePageContent.setHasFixedSize(true);
                        homePageAdapter = new HomePageAdapter(homePageContent, items, context());
                        HeadRecyclerListHomePageContent.setLayoutManager(new LinearLayoutManager(context(), LinearLayoutManager.VERTICAL, false));
                        HeadRecyclerListHomePageContent.setAdapter(homePageAdapter);

                       //finish
}
 @Override
            public void onFailure(Throwable t) {

            }
....

最佳答案

// What i should write here块中应为:
Merchant merchant = response.body();

Merchant类中,应该是GetMerchant返回的字段。

顺便说一句,您的json无效。

08-16 03:15