我正在使用Volley库解析JSON数据,我在ListView中检索数据,但只打印了最后一个值。这是我的实现:
public void getListElem(final Context context) {
apws = new APWSManager(context, new APWSRequestState() {
@Override
public void customURLFinishedDownload(String response) {
// TODO Auto-generated method stub
Log.i("RESPONSE LISTVIEWPARSER : ", response);
try {
JSONObject json = null;
JSONArray array = new JSONArray(response);
for (int j = 0; j < array.length(); j++) {
json = array.getJSONObject(j);
Log.i("JSONOBJECT : ", json.toString());
parseJsonItem(json);
/* myItemList = new ItemObject(json.getString("title"),
json.getString("value_out"), json.getString("picture")); */
// m_ListItem.add(myItemList);
myList.setAdapter(myAdapter);
Log.i("LISTVIEW TITLE", array.getJSONObject(j).getString("title"));
Log.i("LISTVIEW VALUE", array.getJSONObject(j).getString("value_out"));
Log.i("LISTVIEW PICTURE", array.getJSONObject(j).getString("picture"));
}
myAdapter.notifyDataSetChanged();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void customURLFailedDownload(String errorMessage) {
// TODO Auto-generated method stub
Log.i("ERROR REQUEST : ", errorMessage.toString());
}
});
apws.callAPWSRequest("getnews", null, null, TypeMethod.GET, true);
}
private void parseJsonItem(JSONObject item) {
try {
ItemObject itemObject = new ItemObject(item.getString("title"), item.getString("value_out"), item.getString("picture"));
// Ici à la place tu ajoutes ton objet dans ton array
m_ListItem.add(itemObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
我的ListView打印正确但始终具有相同的值(json中的最后一个值)。如何检索ListView的每个项目中的每个值?
谢谢你们!