国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android Studio獲取網絡JSON數據并處理的方法

2019-10-22 18:25:50
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內容如下

1、需要的網絡JSON數據

Android,Studio,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武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 京山县| 桦甸市| 桑植县| 阳春市| 三台县| 安龙县| 武山县| 财经| 临西县| 浦北县| 汶上县| 宁安市| 梅州市| 曲松县| 三江| 五河县| 老河口市| 贞丰县| 灯塔市| 祥云县| 南和县| 芦山县| 平度市| 兴业县| 从江县| 靖州| 富川| 刚察县| 洪洞县| 天台县| 宜丰县| 平安县| 高台县| 丹寨县| 灵璧县| 濉溪县| 嘉鱼县| 民勤县| 革吉县| 堆龙德庆县| 榕江县|