在Android Retrofit中解析动态嵌套数组

时间:2016-12-23 06:53:47

标签: java android json retrofit2

在下面的json中,我可以阅读类别字段。如何阅读效果列表属性 4 1 动态

packageList

到目前为止我做了什么

ContactList.java

packageList

EffectList.java

     {  
   "categories":[  
  {  
     "mcategory_id":"4",
     "mcategory_name":"Band"

  },
  {  
     "mcategory_id":"1",
     "mcategory_name":"Basic Effects"

  },
  {  
     "mcategory_id":"3",
     "mcategory_name":"Bg Image Card"

  }

],
        "effect_list":[{  
  "4":[  
     {  
        "effects_id":"18",
        "effects_name":"Band 1"

     },
     {  
        "effects_id":"19",
        "effects_name":"Band 2"

     }

  ],
  "1":[  
     {  
        "effects_id":"1",
        "effects_name":"Background Blur"

     },
     {  
        "effects_id":"4",
        "effects_name":"Blemish Removal"

     }
    ] 
        } ]  
 }

ApiService.java

   @SerializedName("categories")
@Expose
private List<Category> categories = null;


@SerializedName("effect_list")
@Expose
private Map<String, List<List<EffectList>>> effectlist;

public Map<String, List<List<EffectList>>> getEffectlist() {
    return effectlist;
}

public void setEffectlist(Map<String, List<List<EffectList>>> effectlist) {
    this.effectlist = effectlist;
}


public List<Category> getCategories() {
    return categories;
}

public void setCategories(List<Category> categories) {
    this.categories = categories;
}

现在,我可以阅读类别的属性,但 effect_list 为空。  如何使用改造阅读 4 1 动态效果列表属性?

修改

我正在使用ArrayAdapter来存储列表。我需要在 MyContactAdapter1.java 中做些什么更改?

MyContactAdapter1.java

@SerializedName("effects_id")
@Expose
private String effectsId;

@SerializedName("effects_name")
@Expose
private String effectsName;

public String getEffectsId() {
    return effectsId;
}

public void setEffectsId(String effectsId) {
    this.effectsId = effectsId;
}

public String getEffectsName() {
    return effectsName;
}

public void setEffectsName(String effectsName) {
    this.effectsName = effectsName;
} 

Main.java

 @GET("json_new")
Call<ContactList> getMyJSON();

0 个答案:

没有答案