私は次のように解析してjson
を解析し、ListView
にBaseAdapter
、Androidを使用して表示しようとしています。ここでオブジェクトとはです。です。これらの値が動的でない場合、モデルクラスを作成する方法は分かります。次の方法でjson
を取得しようとしましたが、値は返されません。 Model.java
に間違いはありますか?またはjsonの形式を変更する必要がありますか?Androidで動的jsonオブジェクトを解析する
{
"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"
}
]
}
]
}
Model.java
public class Model{
@SerializedName("effect_list")
@Expose
List<Map<String,List<EffectList>>> effectlist;
public List<Map<String, List<EffectList>>> getEffectlist() {
return effectlist;
}
public void setEffectlist(List<Map<String, List<EffectList>>> effectlist) {
this.effectlist = effectlist;
}
}
EffectList.java
public class EffectList {
@SerializedName("effects_id")
@Expose
private String effectsId;
@SerializedName("effects_name")
@Expose
private String effectsName;
//GETTERS AND SETTERS
}
MyContactAdapter2.java
public class MyContactAdapter2 extends BaseAdapter {
ArrayList<Map<String, List<EffectList>>> contactList;
Context context;
private LayoutInflater mInflater;
public MyContactAdapter2(Context context, ArrayList<Map<String, List<EffectList>>> data) {
this.context = context;
this.mInflater = LayoutInflater.from(context);
contactList = data;
}
@Override
public int getCount() {
return 0;
}
@Override
public List<HashMap<String, List<EffectList>>> getItem(int position) {
return (List<HashMap<String, List<EffectList>>>) contactList.get(position);
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder1 vh1;
if (convertView == null) {
View view = mInflater.inflate(R.layout.get_layout_row_view, parent, false);
vh1 = ViewHolder1.create((RelativeLayout) view);
view.setTag(vh1);
} else {
vh1 = (ViewHolder1) convertView.getTag();
}
EffectList item = (EffectList) getItem(position);
// vh.textViewName.setText(item.getEffectsId());
vh1.textViewName.setText(item.getEffectsName());
vh1.textViewEmail.setText(item.getEffectsId());
// Picasso.with(context).load(item.getProfilePic()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(vh.imageView);
return vh1.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 MyContactAdapter2.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 MyContactAdapter2.ViewHolder1(rootView, imageView, textViewName, textViewEmail);
}
}
}
MyContactAdapter2に間違いがありますか?
可能な複製http://stackoverflow.com/questions/41355969/how-to-parse-following-json-using-gson-in-android –