Android Studio獲取網(wǎng)絡(luò)JSON數(shù)據(jù)并處理的方法
本文實(shí)例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內(nèi)容如下
1、需要的網(wǎng)絡(luò)JSON數(shù)據(jù)

2、數(shù)據(jù)實(shí)現(xiàn)類(lèi)
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;//科室名稱(chēng)
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ù)集名稱(chēng)為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ù)請(qǐng)求失敗,請(qǐng)稍后重試", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
//請(qǐng)求失敗的回調(diào)處理
Toast.makeText(GV_Consultation.this, "請(qǐng)鏈接網(wǎng)絡(luò),稍后重試", Toast.LENGTH_SHORT).show();
}
});
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- android客戶(hù)端從服務(wù)器端獲取json數(shù)據(jù)并解析的實(shí)現(xiàn)代碼
- Android中使用Gson解析JSON數(shù)據(jù)的兩種方法
- Android中的JSON詳細(xì)總結(jié)
- Android網(wǎng)絡(luò)編程之獲取網(wǎng)絡(luò)上的Json數(shù)據(jù)實(shí)例
- Android webview與js交換JSON對(duì)象數(shù)據(jù)示例
- Android訪(fǎng)問(wèn)php取回json數(shù)據(jù)實(shí)例
- Android 解析JSON對(duì)象及實(shí)例說(shuō)明
- Android中生成、使用Json數(shù)據(jù)實(shí)例
- Android中Json數(shù)據(jù)讀取與創(chuàng)建的方法
- android調(diào)用國(guó)家氣象局天氣預(yù)報(bào)接口json數(shù)據(jù)格式解釋
相關(guān)文章
Android基于google Zxing實(shí)現(xiàn)各類(lèi)二維碼掃描效果
這篇文章主要介紹了Android基于google Zxing實(shí)現(xiàn)各類(lèi)二維碼掃描效果的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-02-02
Android開(kāi)發(fā)之OkHttpUtils的具體使用方法
這篇文章主要介紹了Android開(kāi)發(fā)之OkHttpUtils的具體使用方法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-08-08
Android 三種延遲操作的實(shí)現(xiàn)方法
這篇文章主要介紹了Android 延遲操作的實(shí)現(xiàn)方法的相關(guān)資料,這里提供了三種實(shí)現(xiàn)方法,希望能幫助到大家,需要的朋友可以參考下2017-08-08
Android?PopUpWindow實(shí)現(xiàn)卡片式彈窗
大家好,本篇文章主要講的是Android?PopUpWindow實(shí)現(xiàn)卡片式彈窗,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話(huà)記得收藏一下2022-01-01
點(diǎn)擊微信內(nèi)網(wǎng)頁(yè)a標(biāo)簽直接跳轉(zhuǎn)打開(kāi)淘寶APP的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于如何實(shí)現(xiàn)點(diǎn)擊微信內(nèi)網(wǎng)頁(yè)a標(biāo)簽直接跳轉(zhuǎn)打開(kāi)淘寶APP的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧。2017-11-11
Android開(kāi)發(fā)實(shí)現(xiàn)的文本折疊點(diǎn)擊展開(kāi)功能示例
這篇文章主要介紹了Android開(kāi)發(fā)實(shí)現(xiàn)的文本折疊點(diǎn)擊展開(kāi)功能,涉及Android界面布局與屬性控制相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
Android手把手教大家制作APP首頁(yè)(下拉刷新、自動(dòng)加載)
這篇文章主要為大家詳細(xì)介紹了Android手把手教大家制作APP首頁(yè),實(shí)現(xiàn)下拉刷新、自動(dòng)加載功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01
Android中解決RecyclerView各種點(diǎn)擊事件的方法
這篇文章主要介紹了Android中解決RecyclerView各種點(diǎn)擊事件的方法,完美解決RecyclerView點(diǎn)擊事件、長(zhǎng)按事件、子項(xiàng)點(diǎn)擊事件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05

