所有名称都不是从arraylist

时间:2015-06-15 07:11:43

标签: json arraylist

在arraylist上显示Json文件,我想从json文件中显示arraylist中的所有名称。

try {                       
    JSONArray root = new JSONArray(json);

    for (int i = 0; i < root.length(); i++) 
    {
        JSONObject att = (JSONObject) root.getJSONObject(i);
        name  = att.getString("nm");
        list.add(name);

    }
    for(int i = 0; i<root.length(); i++){
      Log.i("name", name);
    }
}catch (JSONException e) {
    e.printStackTrace();
}

1 个答案:

答案 0 :(得分:1)

try{
    JSONArray root = new JSONArray(json);
    for (int i = 0; i < root.length(); i++){
        JSONObject att = (JSONObject) root.getJSONObject(i);
        name = att.getString("nm");
        list.add(name);
    }
    for(int j = 0; j<feedList.size(); j++){
        Log.i("name",feedList.get(j));          
    }   
}catch (JSONException e) {
    e.printStackTrace();
}