馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
為什麼只有size的json抓不到呢? 我想要folder不顯示size 因為沒有json可以抓,然後file的話,就顯示他的size,如圖片這樣
但加了item.put("size", json3); 之後會導致listview全部清空 丟不進去
json格式:- String Result="{"code":200,"body":{"path":"\/","ls":[{"name":"pic","type":"folder"},
- {"name":"testpicc.JPG","type":"file","size":16043,"ctime":1356876932,"mtime":1356876932}]}}"
複製代碼 這邊是我寫的程式碼:- JSONObject jsonObject = new JSONObject(Result).getJSONObject("body");
- JSONArray jsonArray = jsonObject.getJSONArray("ls");
- String[] json = new String[jsonArray.length()];
- String[] json2 = new String[jsonArray.length()];
- String[] json3 = new String[jsonArray.length()];
- for(int i=0;i<jsonArray.length();i++)
- {
- Map<String, Object> item = new HashMap<String, Object>();
- JSONObject jsonObject2 = (JSONObject)jsonArray.opt(i);
- json[i] = jsonObject2.getString("name");
- json2[i] = jsonObject2.getString("type");
- json3[i] = jsonObject2.getString("size");
-
- item.put("name", json[i]);
- item.put("type", json2[i]);
- item.put("size", json3[i]);
- }
- simpleAdapter = new SimpleAdapter(this,items, R.layout.list_content, new String[]{"name","image","size"},new int[]{R.id.user_id, R.id.user_pic, R.id.user_size});
複製代碼
|
![](source/plugin/apk_quickrate/images/kspf.gif)
|