我有以下的json數組。我想用改裝Android - Retrofit json解析
[
{
"todo_id": "1",
"todo_content": "Homework",
"date": "2016-05-05",
"iscomplete": "1",
"imagelink": "Lighthouse.jpg"
},
{
"todo_id": "2",
"todo_content": "exam",
"date": "2015-04-21",
"iscomplete": "0",
"imagelink": "Desert.jpg"
},
{
"todo_id": "3",
"todo_content": "Lab report",
"date": "2014-08-29",
"iscomplete": "1",
"imagelink": "FB_IMG_14700753538617403.jpg"
}
]
當我使用JSON解析改造解析它在android系統,但它不解析todo_id和todo_content關鍵值,其中,因爲它表明其他鍵值日期,iscomplete和ImageLink的 這是我的android代碼改造響應
public void onResponse(Call<List<AndroidVersion>> call, Response<List<AndroidVersion>> response) {
if (response.isSuccess()) {
try {
for (int i = 0; i < response.body().size(); i++) {
AndroidVersion ver = new AndroidVersion();
ver.setTodoContent(response.body().get(i).getTodoContent());
ver.setTodoId(response.body().get(i).getTodoId());
ver.setDate(response.body().get(i).getDate());
ver.setIscomplete(response.body().get(i).getIscomplete());
ver.setImagelink(response.body().get(i).getImagelink());
arrayList.add(ver);
Log.v("ret",response.body().get(i).toString());
}
adapter = new DataAdapter(arrayList);
recyclerView.setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
}
}
}
請發表您的ANDROIDVERSION類 –
使用@SerializedName解析,比你的領域應符合JSON的名字。將json字段名稱放入註釋中。 –