国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

json解析

2019-11-08 00:35:47
字體:
供稿:網(wǎng)友

json和xml的解析有一些類似,將json的內(nèi)容讀入字符串之后 在進(jìn)行解析 json數(shù)據(jù)是:{ }包裹的是JSONObject,對象里面是鍵值對,直接調(diào)用getString()等等就可以 []包裹的是JSONArray

PRivate void parseJSONWithJSONObject(String jsonData){ try{ //JSONArray jsonArray = new JSONArray(jsonData); JSONObject jsonObject = new JSONObject(jsonData); String str1 = jsonObject.getString("stories"); String str2 = jsonObject.getString("top_stories"); JSONArray jsonArray1 = new JSONArray(str1); JSONArray jsonArray2 = new JSONArray(str2); for(int i=0;i<jsonArray1.length();i++){ JSONObject jsonObject1 = jsonArray1.getJSONObject(i); int type = jsonObject1.getInt("type"); int id = jsonObject1.getInt("id"); String title = jsonObject1.getString("title"); Why temp = new Why(type,id,title); // String list = "type : "+type+" id : "+id+" title : "+title; data.add(temp); /* Log.d("type",""+type); Log.d("id",""+id); Log.d("title",title);*/ } for(int i=0;i<jsonArray2.length();i++){ JSONObject jsonObject2 = jsonArray2.getJSONObject(i); int type = jsonObject2.getInt("type"); int id = jsonObject2.getInt("id"); String title = jsonObject2.getString("title"); Why temp = new Why(type,id,title); // String list = "type : "+type+" id : "+id+" title : "+title; data.add(temp); /* Log.d("type",""+type); Log.d("id",""+id); Log.d("title",title);*/ } }catch (Exception e){ e.printStackTrace(); } }
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 株洲市| 温泉县| 酒泉市| 内黄县| 龙海市| 清苑县| 含山县| 枞阳县| 闽清县| 阿拉善左旗| 石屏县| 沈丘县| 中阳县| 太仓市| 梁河县| 庄河市| 蕲春县| 正蓝旗| 蒲江县| 曲松县| 松阳县| 如皋市| 壶关县| 霍林郭勒市| 万全县| 昌宁县| 上杭县| 凤阳县| 图木舒克市| 兰溪市| 高邑县| 大悟县| 南宁市| 诸暨市| 麻城市| 临洮县| 贺兰县| 前郭尔| 乌鲁木齐市| 关岭| 醴陵市|