private Handler getJsonHandler = new Handler(){ public void handleMessage(android.os.Message msg) { String jsonData = (String) msg.obj; System.out.println(jsonData); try { JSONArray jsonArray = new JSONArray(jsonData); Log.i("jsonArray.length",jsonArray.length()+""); for (int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); snacks_name = object.getString("snacks_name"); snacks_short_desc = object.getString("snacks_short_desc"); snacks_detail_desc = object.getString("snacks_detail_desc"); img_url_top = object.getString("img_url_top"); img_url_main = object.getString("img_url_main"); img_url_buttom = object.getString("img_url_buttom"); post_time = object.getString("post_time"); detail_text01 = object.getString("detail_text01"); detail_text02 = object.getString("detail_text02"); img_url_main01 = object.getString("img_url_main01"); img_url_main02 = object.getString("img_url_main02"); snacksList.add(0,new Snacks(snacks_name, snacks_short_desc, snacks_detail_desc, img_url_top, img_url_main, img_url_buttom, post_time, detail_text01, detail_text02, img_url_main01, img_url_main02)); // newsList.add(new News(title, desc, time, content_url, pic_url)); } adapter.notifyDataSetChanged(); switch (msg.what) { case REFRESH_COMPLETE: // mDatas.addAll(Arrays.asList("Lucene", "Canvas", "Bitmap")); //HttpUtils.getNewsJSON(GET_JSON, getJsonHandler); // snacksList.add(new Snacks("aaa", "aaa", "aaa", "http://f.hiphotos.baidu.com/zhidao/pic/item/38dbb6fd5266d016840de4e7962bd40734fa35ec.jpg", "http://f.hiphotos.baidu.com/zhidao/pic/item/38dbb6fd5266d016840de4e7962bd40734fa35ec.jpg", "http://f.hiphotos.baidu.com/zhidao/pic/item/38dbb6fd5266d016840de4e7962bd40734fa35ec.jpg", "2015-04-10 18:31:28")); if(jsonData==null){ break; }else { adapter.notifyDataSetChanged(); mSwipeLayout.setRefreshing(false); break; } } } catch (Exception e) { e.printStackTrace(); } }; };
附上下载链接 点击打开链接