【问题标题】:Json object multiple array Parse, retrofitJson对象多数组Parse,改造
【发布时间】:2017-09-02 10:47:27
【问题描述】:

我有一个 Json 字符串。我无法使用带有两个列表(类别和产品)的改造来响应。我怎么打电话,回拨?我应该用什么?通常不是一个列表,对吧?

{
"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) {

            }
....

【问题讨论】:

  • 你想知道如何将 JSON 解析成 POJO 吗?
  • @AishwaryaTiwari 我编辑问题。不,不是 POJO。我想知道我如何列出清单?谢谢
  • 您的 JSON 无效。检查您的 JSON 在 JSONLint 上是否有效。发布一个有效的 JSON,然后我们可以提供适当的帮助。

标签: android json android-recyclerview gson retrofit


【解决方案1】:

// What i should write here 块中应该是这样的: Merchant merchant = response.body();

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

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

【讨论】:

  • 不,我编辑问题。我想知道,如何放入 json 列表中?因为我在 json 上有 2 个列表(类别和 ProductItems)
  • 您应该使用您的两个列表和来自 json 结构的其他字段创建类,然后创建此类的实例并填充字段。当您可以像使用 GetMerchant 请求一样通过改造发送此对象时@Jenni
猜你喜欢
  • 2017-08-02
  • 1970-01-01
  • 2017-05-12
  • 1970-01-01
  • 2019-04-26
  • 2016-11-02
  • 2017-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多