我有一个Json字符串。我无法使用两个List(类别和产品)进行Retrofit的响应。我怎么称呼,回调?我应该用什么?不是一般的清单,对吗?
{
"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) {
}
....
答案 0 :(得分:0)
在块// What i should write here
中应该是这样的:
Merchant merchant = response.body();
在Merchant
中,类应该是GetMerchant
返回的字段。
你的json无效。