国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 瓮安县| 松江区| 北海市| 广水市| 安阳市| 南丹县| 龙海市| 永昌县| 大姚县| 扶余县| 凤阳县| 汕尾市| 浙江省| 大渡口区| 宜宾县| 汉寿县| 鄄城县| 依安县| 山阴县| 县级市| 佳木斯市| 磴口县| 北海市| 两当县| 东乌珠穆沁旗| 黎川县| 鲜城| 平谷区| 星座| 安顺市| 鹤壁市| 乾安县| 隆德县| 南涧| 嘉义市| 水城县| 塔河县| 社会| 白城市| 永登县| 定结县|