通过http://blog.youkuaiyun.com/vincent_czz/article/details/7333977,找到了自己所需要的,--->写的更全面, 我写的是自己需要的部分 -----android菜鸟
json 语句:{
"state": "OK",
"type": [
{
"add_time": "2015-10-14",
"attr_id": "86",
"attr_name": "五金工具",
"image": "http://www.layib.com/data/files/marchine_type/9155151.jpg",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "87",
"attr_name": "市政园林",
"image": "http://www.layib.com/data/files/marchine_type/7042480.jpg",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "88",
"attr_name": "起重机械",
"image": "http://www.layib.com/data/files/marchine_type/7828002.jpg",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "89",
"attr_name": "工业车辆",
"image": "http://www.layib.com/data/files/marchine_type/5010833.jpg",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "90",
"attr_name": "路面设备",
"image": "http://www.layib.com/data/files/marchine_type/7391571.jpg",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "91",
"attr_name": "能源设备",
"image": "http://www.layib.com/data/files/marchine_type/8926086.jpg",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "92",
"attr_name": "路面设备",
"image": "http://www.layib.com/",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "93",
"attr_name": "物料运输",
"image": "http://www.layib.com/data/files/marchine_type/2378234.jpg",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "94",
"attr_name": "高空作业",
"image": "http://www.layib.com/data/files/marchine_type/7522308.jpg",
"parent_id": "79",
"sort_order": "255"
},
{
"add_time": "2015-10-26",
"attr_id": "95",
"attr_name": "建筑建材",
"image": "http://www.layib.com/data/files/marchine_type/1149139.jpg",
"parent_id": "79",
"sort_order": "255"
}
]
}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
使用的xutils获取的json语句
private List<String> getWuZiShaiXuanData(){ List<String> wuziShaiXuanData = new ArrayList<>(); HttpUtils httpUtils = new HttpUtils(); httpUtils.send(HttpRequest.HttpMethod.GET, Utils.WUZI_ZULIN, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { String result = responseInfo.result; try { JSONObject jsonObject = new JSONObject(result); JSONArray typeList = jsonObject.getJSONArray("type"); int length = typeList.length(); for (int i = 0;i<length;i++){ JSONObject oj = typeList.getJSONObject(i);
String name = (String) oj.get("attr_name"); wuziShaiXuanData.add(name); } Toast.makeText(BaseActivity.this,wuziShaiXuanData.toString(),Toast.LENGTH_SHORT).show(); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(HttpException e, String s) { } }); return wuziShaiXuanData; }
二.碰到的另一种json语句
{ "state": "OK", "type": { "100": "xx组", "101": "xx组", "102": "xx组", "103": "xx组", "104": "xx组", "105": "xx组", "65": "xx组", "66": "xx组", "97": "xx组", "98": "xx组", "99": "xx组" } }
我自己的解析方式:
httpUtils.send(HttpRequest.HttpMethod.GET, Utils.BANZU_TYPE, new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { String result = responseInfo.result; try { JSONObject jsonObject = new JSONObject(result); String result_type = jsonObject.getString("type"); jsonObject = new JSONObject(result_type); Iterator<String> iterator = jsonObject.keys(); while (iterator.hasNext()) { String key = iterator.next(); String value = jsonObject.getString(key); banzuData.add(value); // List<String> banzuData banzuDataTypeHashMap.put(value,key); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(HttpException e, String s) { } });