gpt4 book ai didi

android - Json对象多数组解析、改造

转载 作者:行者123 更新时间:2023-11-29 02:42:18 27 4
gpt4 key购买 nike

我有一个 Json 字符串。我无法使用带有两个列表(类别和产品)的 Retrofit 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 block 中应该是这样的:商户merchant = response.body();

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

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

关于android - Json对象多数组解析、改造,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43271537/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com