編輯:關於android開發
在android開發過程中,難免會遇到json解析,在這篇文章中為你快速解析復雜的json。
首先,在android studio中安裝gsonformat插件。
點擊File->Settings->Plugins
安裝後重啟android studio
接下來,新建工程,導入gson。
File->Project Structure->
點擊“+”,->Library dependency
選擇GSON
解析來就是解析json了。
網上json例子:
{"payCnt":3, "payInfo":[ {"payInfoMain":{"ordNum":"201206010000001","transSite":"","transBankNo":"TEPB","bankAcctNo":"010","totAmt":"30","billChkCode":"3316","tollDeptNo":"NDZSXH000","busType":"FJFS","other1":"remark1","other2":"remark2","bankName":"模擬銀行2","transSeq":"20120601000000001","tranType":"","siteCode":"200001","eBillVerNo":"000001","tollDeptName":"寧德市會計專業技術考試領導小組","itemCnt":1,"tranUser":"","payer":"寧德","eBillNo":"201206010000000136","transBankName":"模擬銀行2","transAcctNo":"010","siteName":"國家司法考試網","ordDate":"20120601"}, "eBillNo":"201206010000000136", "payInfoItem":[{"amt":"30","chrgStd":"1","cnt":"1","chrgName":"初級網絡工程師報名費","msrUint":"元/科","chrgCode":"KA460001"}]}, {"payInfoMain":{"ordNum":"201206010000001","transSite":"","transBankNo":"TEPB","bankAcctNo":"010","totAmt":"10","billChkCode":"2258","tollDeptNo":"777516727","busType":"FJFS","other1":"remark1","other2":"remark2","bankName":"模擬銀行2","transSeq":"20120601000000001","tranType":"","siteCode":"200001","eBillVerNo":"000001","tollDeptName":"福建省省會計管理處","itemCnt":1,"tranUser":"","payer":"繳款人","eBillNo":"201206010000000134","transBankName":"模擬銀行2","transAcctNo":"010","siteName":"國家司法考試網","ordDate":"20120601"}, "eBillNo":"201206010000000134", "payInfoItem":[{"amt":"10","chrgStd":"1","cnt":"1","chrgName":"交通罰沒","msrUint":"元/科","chrgCode":"460"}]}, {"payInfoMain":{"ordNum":"201206010000001","transSite":"","transBankNo":"TEPB","bankAcctNo":"010","totAmt":"20","billChkCode":"0198","tollDeptNo":"003604520","busType":"FJFS","other1":"remark1","other2":"remark2","bankName":"模擬銀行2","transSeq":"20120601000000001","tranType":"","siteCode":"200001","eBillVerNo":"000001","tollDeptName":"福州市財政局會計管理處","itemCnt":1,"tranUser":"","payer":"福州","eBillNo":"201206010000000135","transBankName":"模擬銀行2","transAcctNo":"010","siteName":"國家司法考試網","ordDate":"20120601"}, "eBillNo":"201206010000000135", "payInfoItem":[{"amt":"20","chrgStd":"1","cnt":"1","chrgName":"會計從業資格證考務費","msrUint":"元/科","chrgCode":"BA460"}]}]}
新建一個Bean,右鍵Gerenate->GsonFormat,將json串復制進去
注意:如果需要新建內部類的話需要與字段名稱相同
創建完Bean類後,就可以使用gson來解析了。
在MainActivity中調用
Gson mGson=new Gson();
Bean bean=mGson.fromJson(json,Bean.class);
Log.i("Debug",bean.getPayInfo().get(0).getPayInfoItem().get(0).getChrgName());
看看解析的結果吧
是不是很方便呢
手機影音6--視頻播放器的基本功能(3),6--基本功能 1.自定義VideoView 1_自定義VideoView-增加設置視頻大小方法 public class V
Android github 快速實現多人協作,androidgithub前言:最近要做github多人協作,也就是多人開發。搜索了一些資料,千篇一律,而且操作麻煩。今天
圓形背景的TextView,圓形背景TextView【應用場景】: 【需要的xml】:shape_circle.xml <?xml version=1.0 enc
Android制作粒子爆炸特效 簡介 最近在閒逛的時候,發現了一款粒子爆炸特效的控件,覺得比較有意思,效果也不錯。 但是代碼不好擴展,也就是說如果要提供不同的爆炸效果