好吧,我只是想将 json web-service 解析为一个数组,问题只是列表视图上显示的第一项。我应该怎么做才能使完整的 json 数组出现在列表视图中?
private void makeJsonObjectRequest() {
showpDialog();
final JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
urlJsonObj, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
try {
JSONArray snap = response.getJSONArray("arr_0");
String[] list = new String[snap.length()];
for (int i = 0; i < snap.length(); i++) {
list[i] = snap.getJSONObject(i).getString("title");
list[i] = snap.getJSONObject(i).getString("description");
list[i] = snap.getJSONObject(i).getString("url");
list[i] = snap.getJSONObject(i).getString("sort");
list[i] = snap.getJSONObject(i).getString("attachment_id");
list[i] = snap.getJSONObject(i).getString("thumb");
list[i] = snap.getJSONObject(i).getString("image");
list[i] = snap.getJSONObject(i).getString("height");
list[i] = snap.getJSONObject(i).getString("width");
}
snapActivity.this.lv.setAdapter(new ArrayAdapter(snapActivity.this,android.R.layout.simple_list_item_1, list));
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
hidepDialog();
}