欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android Studio獲取網(wǎng)絡(luò)JSON數(shù)據(jù)并處理的方法

 更新時間:2017年10月13日 09:14:30   作者:龍魂學(xué)者  
這篇文章主要為大家詳細(xì)介紹了Android Studio獲取網(wǎng)絡(luò)JSON數(shù)據(jù)并處理的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

1、需要的網(wǎng)絡(luò)JSON數(shù)據(jù)

這里寫圖片描述

2、數(shù)據(jù)實現(xiàn)類

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、創(chuàng)建List集合接收數(shù)據(jù)

List<BasSection> listBasSection = new ArrayList<>();

4、獲取JSON數(shù)據(jù)

/**
 * 獲取JSON科室數(shù)據(jù)
 */
public void findSectionData(){
  AsyncHttpClient client = new AsyncHttpClient();
  //你的JSON數(shù)據(jù)鏈接地址
  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數(shù)據(jù)
        JSONArray jsonArray = object.getJSONArray("obj");//獲取數(shù)據(jù)集名稱為obj的數(shù)據(jù)
        Log.d("jsonArray數(shù)據(jù)輸出:", String.valueOf(jsonArray));
        for (int i = 0; i < jsonArray.length();i++) {
          BasSection novels = BasSection.sectionData(jsonArray.getJSONObject(i));//把數(shù)據(jù)存在novels集合中
          if (novels != null){
            listBasSection.add(novels);
          }
        }

      } catch (JSONException e) {
        Toast.makeText(GV_Consultation.this, "數(shù)據(jù)請求失敗,請稍后重試", Toast.LENGTH_SHORT).show();
      }
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
      //請求失敗的回調(diào)處理
      Toast.makeText(GV_Consultation.this, "請鏈接網(wǎng)絡(luò),稍后重試", Toast.LENGTH_SHORT).show();
    }
  });
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論