2017-04-07 7 views
1

私はJson文字列を持っています。私は2つのリスト(カテゴリと製品)でRetrofitでonResponseできませんでした。コールバック、コールバック私は何を使うべきですか?通常はリストではないでしょうか?通常でJsonオブジェクト複数の配列Parse、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 
 
    } 
 

私は

ブロック// What i should write here

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

JSONをPOJOに解析する方法を知りたいですか? –

+0

@AishwaryaTiwari私はquesitonを編集します。いいえ、POJOではありません。私はどのようにリストを置くのか知りたいですか?ありがとうございます – Jenni

+0

JSONが無効です。 JSONが[JSONLint](http://jsonlint.com/)で有効かどうかを確認してください。有効なJSONを投稿すると、適切に対応できます。 –

答えて

0

このなければならないことを実行します。 Merchant merchant = response.body();

Merchantクラスは、GetMerchantが返すフィールドである必要があります。

あなたのjsonは無効です。

+0

いいえ、私は質問を編集します。私は知ってほしい、どのようにjsonの1つのリストに入れた?私は2つのリストをjson(CategoriesとProductItems)に持っていますから – Jenni

+0

あなたはこのクラスのインスタンスを作成してフィールドを記入した後に、2つのリストと他のフィールドをjson構造から作成する必要があります。あなたがGetMerchantリクエスト@Jenniと同様にこのオブジェクトをretrofit経由で送ることができるとき – shmakova

関連する問題