Java Android改造中的动态嵌套数组解析

Java Android改造中的动态嵌套数组解析,java,android,json,retrofit2,Java,Android,Json,Retrofit2,在下面的json中,我能够读取类别字段。如何读取动态属性4和1 { "categories":[ { "mcategory_id":"4", "mcategory_name":"Band" }, { "mcategory_id":"1", "mcategory_name":"Basic Effects" }, { "mcategory_id":"3", "mcategory_n

在下面的json中,我能够读取类别字段。如何读取动态属性41

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

     }
    ] 
        } ]  
 }
到目前为止我做了什么

ContactList.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;
}
@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;
} 
 @GET("json_new")
Call<ContactList> getMyJSON();
List<EffectList> contactList;
Context context;
private LayoutInflater mInflater;


// Constructors
public MyContactAdapter1(Context context, List<EffectList> objects) {
    super(context, 0, objects);
    this.context = context;
    this.mInflater = LayoutInflater.from(context);
    contactList = objects;
}

@Override
public EffectList getItem(int position) {
    return contactList.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final MyContactAdapter1.ViewHolder1 vh;
    if (convertView == null) {
        View view = mInflater.inflate(R.layout.get_layout_row_view, parent, false);
        vh = MyContactAdapter1.ViewHolder1.create((RelativeLayout) view);
        view.setTag(vh);
    } else {
        vh = (MyContactAdapter1.ViewHolder1) convertView.getTag();
    }

    EffectList item = getItem(position);



    //   vh.textViewName.setText(item.getEffectsId());

    vh.textViewName.setText(item.getEffectsName());
    vh.textViewEmail.setText(item.getEffectsId());
    // Picasso.with(context).load(item.getProfilePic()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(vh.imageView);

    return vh.rootView;
}

private static class ViewHolder1 {
    public final RelativeLayout rootView;
    public final ImageView imageView;
    public final TextView textViewName;
    public final TextView textViewEmail;

    private ViewHolder1(RelativeLayout rootView, ImageView imageView, TextView textViewName, TextView textViewEmail) {
        this.rootView = rootView;
        this.imageView = imageView;
        this.textViewName = textViewName;
        this.textViewEmail = textViewEmail;
    }

    public static MyContactAdapter1.ViewHolder1 create(RelativeLayout rootView) {
        ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
        TextView textViewName = (TextView) rootView.findViewById(R.id.textViewName);
        TextView textViewEmail = (TextView) rootView.findViewById(R.id.textViewEmail);
        return new MyContactAdapter1.ViewHolder1(rootView, imageView, textViewName, textViewEmail);
    }
}
  call.enqueue(new Callback<ContactList>() {
        @Override
        public void onResponse(Call<ContactList> call, Response<ContactList> response) {                 

            if (response.isSuccessful()) {     

                Toast.makeText(getApplicationContext(),"Response Success",Toast.LENGTH_LONG).show();
                Log.d("RESPONSE: ", contactList1.toString());

                contactList = (List<Map<String,List<EffectList>>>) response.body().getEffectlist();
                adapter = new MyContactAdapter1(uploadpage.this, contactList);
                listView.setAdapter(adapter);


            } else {

            }
        }
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;
}
@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;
} 
 @GET("json_new")
Call<ContactList> getMyJSON();
List<EffectList> contactList;
Context context;
private LayoutInflater mInflater;


// Constructors
public MyContactAdapter1(Context context, List<EffectList> objects) {
    super(context, 0, objects);
    this.context = context;
    this.mInflater = LayoutInflater.from(context);
    contactList = objects;
}

@Override
public EffectList getItem(int position) {
    return contactList.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final MyContactAdapter1.ViewHolder1 vh;
    if (convertView == null) {
        View view = mInflater.inflate(R.layout.get_layout_row_view, parent, false);
        vh = MyContactAdapter1.ViewHolder1.create((RelativeLayout) view);
        view.setTag(vh);
    } else {
        vh = (MyContactAdapter1.ViewHolder1) convertView.getTag();
    }

    EffectList item = getItem(position);



    //   vh.textViewName.setText(item.getEffectsId());

    vh.textViewName.setText(item.getEffectsName());
    vh.textViewEmail.setText(item.getEffectsId());
    // Picasso.with(context).load(item.getProfilePic()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(vh.imageView);

    return vh.rootView;
}

private static class ViewHolder1 {
    public final RelativeLayout rootView;
    public final ImageView imageView;
    public final TextView textViewName;
    public final TextView textViewEmail;

    private ViewHolder1(RelativeLayout rootView, ImageView imageView, TextView textViewName, TextView textViewEmail) {
        this.rootView = rootView;
        this.imageView = imageView;
        this.textViewName = textViewName;
        this.textViewEmail = textViewEmail;
    }

    public static MyContactAdapter1.ViewHolder1 create(RelativeLayout rootView) {
        ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
        TextView textViewName = (TextView) rootView.findViewById(R.id.textViewName);
        TextView textViewEmail = (TextView) rootView.findViewById(R.id.textViewEmail);
        return new MyContactAdapter1.ViewHolder1(rootView, imageView, textViewName, textViewEmail);
    }
}
  call.enqueue(new Callback<ContactList>() {
        @Override
        public void onResponse(Call<ContactList> call, Response<ContactList> response) {                 

            if (response.isSuccessful()) {     

                Toast.makeText(getApplicationContext(),"Response Success",Toast.LENGTH_LONG).show();
                Log.d("RESPONSE: ", contactList1.toString());

                contactList = (List<Map<String,List<EffectList>>>) response.body().getEffectlist();
                adapter = new MyContactAdapter1(uploadpage.this, contactList);
                listView.setAdapter(adapter);


            } else {

            }
        }
@GET(“json_new”)
调用getMyJSON();
现在我可以读取类别的属性,但是效果列表为空。 如何阅读效果列表属性,其中41动态的

编辑:

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

MyContactAdapter1.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;
}
@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;
} 
 @GET("json_new")
Call<ContactList> getMyJSON();
List<EffectList> contactList;
Context context;
private LayoutInflater mInflater;


// Constructors
public MyContactAdapter1(Context context, List<EffectList> objects) {
    super(context, 0, objects);
    this.context = context;
    this.mInflater = LayoutInflater.from(context);
    contactList = objects;
}

@Override
public EffectList getItem(int position) {
    return contactList.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final MyContactAdapter1.ViewHolder1 vh;
    if (convertView == null) {
        View view = mInflater.inflate(R.layout.get_layout_row_view, parent, false);
        vh = MyContactAdapter1.ViewHolder1.create((RelativeLayout) view);
        view.setTag(vh);
    } else {
        vh = (MyContactAdapter1.ViewHolder1) convertView.getTag();
    }

    EffectList item = getItem(position);



    //   vh.textViewName.setText(item.getEffectsId());

    vh.textViewName.setText(item.getEffectsName());
    vh.textViewEmail.setText(item.getEffectsId());
    // Picasso.with(context).load(item.getProfilePic()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(vh.imageView);

    return vh.rootView;
}

private static class ViewHolder1 {
    public final RelativeLayout rootView;
    public final ImageView imageView;
    public final TextView textViewName;
    public final TextView textViewEmail;

    private ViewHolder1(RelativeLayout rootView, ImageView imageView, TextView textViewName, TextView textViewEmail) {
        this.rootView = rootView;
        this.imageView = imageView;
        this.textViewName = textViewName;
        this.textViewEmail = textViewEmail;
    }

    public static MyContactAdapter1.ViewHolder1 create(RelativeLayout rootView) {
        ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
        TextView textViewName = (TextView) rootView.findViewById(R.id.textViewName);
        TextView textViewEmail = (TextView) rootView.findViewById(R.id.textViewEmail);
        return new MyContactAdapter1.ViewHolder1(rootView, imageView, textViewName, textViewEmail);
    }
}
  call.enqueue(new Callback<ContactList>() {
        @Override
        public void onResponse(Call<ContactList> call, Response<ContactList> response) {                 

            if (response.isSuccessful()) {     

                Toast.makeText(getApplicationContext(),"Response Success",Toast.LENGTH_LONG).show();
                Log.d("RESPONSE: ", contactList1.toString());

                contactList = (List<Map<String,List<EffectList>>>) response.body().getEffectlist();
                adapter = new MyContactAdapter1(uploadpage.this, contactList);
                listView.setAdapter(adapter);


            } else {

            }
        }
列出联系人列表;
语境;
私人停车场;
//建设者
公共MyContactAdapter1(上下文、列表对象){
超级(上下文,0,对象);
this.context=上下文;
this.mInflater=LayoutInflater.from(上下文);
联系人列表=对象;
}
@凌驾
public EffectList getItem(int位置){
返回联系人列表。获取(位置);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
最终MyContactAdapter1.ViewHolder1 vh;
if(convertView==null){
视图视图=mInflater.flate(R.layout.get\u layout\u row\u视图,父视图,false);
vh=MyContactAdapter1.ViewHolder1.create((RelativeLayout)视图);
视图.设置标签(vh);
}否则{
vh=(MyContactAdapter1.ViewHolder1)convertView.getTag();
}
EffectList item=getItem(位置);
//vh.textViewName.setText(item.getEffectsId());
vh.textViewName.setText(item.getEffectsName());
vh.textViewEmail.setText(item.getEffectsId());
//Picasso.with(context).load(item.getProfilePic()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(vh.imageView);
返回vh.rootView;
}
私有静态类ViewHolder1{
公共最终相对论Yout rootView;
公共最终图像视图;
公共最终文本视图文本视图名称;
公开最终文本查看文本查看电子邮件;
private ViewHolder1(RelativeLayout rootView、ImageView ImageView、TextView textViewName、TextView textViewEmail){
this.rootView=rootView;
this.imageView=imageView;
this.textViewName=textViewName;
this.textViewEmail=textViewEmail;
}
公共静态MyContactAdapter1.ViewHolder1创建(RelativeLayout rootView){
ImageView ImageView=(ImageView)rootView.findViewById(R.id.ImageView);
TextView textViewName=(TextView)rootView.findViewById(R.id.textViewName);
TextView textViewEmail=(TextView)rootView.findViewById(R.id.textViewEmail);
返回新的MyContactAdapter1.ViewHolder1(rootView、imageView、textViewName、textViewEmail);
}
}
Main.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;
}
@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;
} 
 @GET("json_new")
Call<ContactList> getMyJSON();
List<EffectList> contactList;
Context context;
private LayoutInflater mInflater;


// Constructors
public MyContactAdapter1(Context context, List<EffectList> objects) {
    super(context, 0, objects);
    this.context = context;
    this.mInflater = LayoutInflater.from(context);
    contactList = objects;
}

@Override
public EffectList getItem(int position) {
    return contactList.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final MyContactAdapter1.ViewHolder1 vh;
    if (convertView == null) {
        View view = mInflater.inflate(R.layout.get_layout_row_view, parent, false);
        vh = MyContactAdapter1.ViewHolder1.create((RelativeLayout) view);
        view.setTag(vh);
    } else {
        vh = (MyContactAdapter1.ViewHolder1) convertView.getTag();
    }

    EffectList item = getItem(position);



    //   vh.textViewName.setText(item.getEffectsId());

    vh.textViewName.setText(item.getEffectsName());
    vh.textViewEmail.setText(item.getEffectsId());
    // Picasso.with(context).load(item.getProfilePic()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(vh.imageView);

    return vh.rootView;
}

private static class ViewHolder1 {
    public final RelativeLayout rootView;
    public final ImageView imageView;
    public final TextView textViewName;
    public final TextView textViewEmail;

    private ViewHolder1(RelativeLayout rootView, ImageView imageView, TextView textViewName, TextView textViewEmail) {
        this.rootView = rootView;
        this.imageView = imageView;
        this.textViewName = textViewName;
        this.textViewEmail = textViewEmail;
    }

    public static MyContactAdapter1.ViewHolder1 create(RelativeLayout rootView) {
        ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
        TextView textViewName = (TextView) rootView.findViewById(R.id.textViewName);
        TextView textViewEmail = (TextView) rootView.findViewById(R.id.textViewEmail);
        return new MyContactAdapter1.ViewHolder1(rootView, imageView, textViewName, textViewEmail);
    }
}
  call.enqueue(new Callback<ContactList>() {
        @Override
        public void onResponse(Call<ContactList> call, Response<ContactList> response) {                 

            if (response.isSuccessful()) {     

                Toast.makeText(getApplicationContext(),"Response Success",Toast.LENGTH_LONG).show();
                Log.d("RESPONSE: ", contactList1.toString());

                contactList = (List<Map<String,List<EffectList>>>) response.body().getEffectlist();
                adapter = new MyContactAdapter1(uploadpage.this, contactList);
                listView.setAdapter(adapter);


            } else {

            }
        }
call.enqueue(新回调(){
@凌驾
public void onResponse(调用调用,响应响应){
if(response.issusccessful()){
Toast.makeText(getApplicationContext(),“响应成功”,Toast.LENGTH_LONG.show();
Log.d(“响应:,contactList1.toString());
contactList=(List)response.body().getEffectlist();
适配器=新的MyContactAdapter1(uploadpage.this,contactList);
setAdapter(适配器);
}否则{
}
}

根据json尝试将
private Map effectlist;
更改为
private list谢谢你的回答。在MyContactAdapter1.java和Main.java中我需要做哪些更改?在Main.java中,一切似乎都很好,但我不明白你试图在适配器构造函数中传递什么