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í)有所幫助,也希望大家多多支持腳本之家。
- android客戶端從服務(wù)器端獲取json數(shù)據(jù)并解析的實現(xiàn)代碼
- Android中使用Gson解析JSON數(shù)據(jù)的兩種方法
- Android中的JSON詳細(xì)總結(jié)
- Android網(wǎng)絡(luò)編程之獲取網(wǎng)絡(luò)上的Json數(shù)據(jù)實例
- Android webview與js交換JSON對象數(shù)據(jù)示例
- Android訪問php取回json數(shù)據(jù)實例
- Android 解析JSON對象及實例說明
- Android中生成、使用Json數(shù)據(jù)實例
- Android中Json數(shù)據(jù)讀取與創(chuàng)建的方法
- android調(diào)用國家氣象局天氣預(yù)報接口json數(shù)據(jù)格式解釋
相關(guān)文章
Android基于google Zxing實現(xiàn)各類二維碼掃描效果
這篇文章主要介紹了Android基于google Zxing實現(xiàn)各類二維碼掃描效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-02-02Android開發(fā)之OkHttpUtils的具體使用方法
這篇文章主要介紹了Android開發(fā)之OkHttpUtils的具體使用方法,非常具有實用價值,需要的朋友可以參考下2017-08-08Android?PopUpWindow實現(xiàn)卡片式彈窗
大家好,本篇文章主要講的是Android?PopUpWindow實現(xiàn)卡片式彈窗,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下2022-01-01點擊微信內(nèi)網(wǎng)頁a標(biāo)簽直接跳轉(zhuǎn)打開淘寶APP的方法實例
這篇文章主要給大家介紹了關(guān)于如何實現(xiàn)點擊微信內(nèi)網(wǎng)頁a標(biāo)簽直接跳轉(zhuǎn)打開淘寶APP的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。2017-11-11Android開發(fā)實現(xiàn)的文本折疊點擊展開功能示例
這篇文章主要介紹了Android開發(fā)實現(xiàn)的文本折疊點擊展開功能,涉及Android界面布局與屬性控制相關(guān)操作技巧,需要的朋友可以參考下2019-03-03Android手把手教大家制作APP首頁(下拉刷新、自動加載)
這篇文章主要為大家詳細(xì)介紹了Android手把手教大家制作APP首頁,實現(xiàn)下拉刷新、自動加載功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01Android中解決RecyclerView各種點擊事件的方法
這篇文章主要介紹了Android中解決RecyclerView各種點擊事件的方法,完美解決RecyclerView點擊事件、長按事件、子項點擊事件,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-05-05