本文實例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內容如下
1、需要的網絡JSON數據

2、數據實現類
package chenglong.activitytest.pengintohospital.entity;import org.json.JSONException;import org.json.JSONObject;/** * * 科室 * Created by LICHENGLONG on 2017-10-02. */public class BasSection { public Integer id;//科室id public String sectionName;//科室名稱 public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getSectionName() { return sectionName; } public void setSectionName(String sectionName) { this.sectionName = sectionName; } public BasSection(Integer id, String sectionName){ this.id = id; this.sectionName = sectionName; } public static BasSection sectionData(JSONObject json){ try { return new BasSection( json.getInt("id"), json.getString("sectionName"); } catch (JSONException e) { e.printStackTrace(); } return null; }}3、創建List集合接收數據
List<BasSection> listBasSection = new ArrayList<>();
4、獲取JSON數據
/** * 獲取JSON科室數據 */public void findSectionData(){ AsyncHttpClient client = new AsyncHttpClient(); //你的JSON數據鏈接地址 client.get(AbAppConfig.DATA_URL + "appGVConsultation/findSectionData", null, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { try { JSONObject object = new JSONObject(new String(responseBody));//獲取json數據 JSONArray jsonArray = object.getJSONArray("obj");//獲取數據集名稱為obj的數據 Log.d("jsonArray數據輸出:", String.valueOf(jsonArray)); for (int i = 0; i < jsonArray.length();i++) { BasSection novels = BasSection.sectionData(jsonArray.getJSONObject(i));//把數據存在novels集合中 if (novels != null){ listBasSection.add(novels); } } } catch (JSONException e) { Toast.makeText(GV_Consultation.this, "數據請求失敗,請稍后重試", Toast.LENGTH_SHORT).show(); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { //請求失敗的回調處理 Toast.makeText(GV_Consultation.this, "請鏈接網絡,稍后重試", Toast.LENGTH_SHORT).show(); } });}以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答