龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

对比分析json及XML(12)

时间:2014-12-03 03:00来源:网络整理 作者:网络 点击:
分享到:
复制代码 代码如下: public void getJsonObjectString(String url) { mQueue = VideoApplication.getInstance().getRequestQueue(); JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Metho

复制代码 代码如下:

public void getJsonObjectString(String url) {
    mQueue = VideoApplication.getInstance().getRequestQueue();
    JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null,
    new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            MyLog.e(TAG, "response = " + response.toString());
            JSONArray jsonArray = null;
            JSONObject jsonObject = null;
            try {
                jsonObject = response.getJSONObject("response");
                jsonArray = jsonObject.getJSONObject("result").getJSONArray("album");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            if (jsonArray == null) {
                return;
            }
            mChannelList = VideoUtils.parseVideoJsonArray(jsonArray);
            if (isLoading) {
                isLoading = false;
                if (mIsGrid) {
                    mChannelGridAdapter.appendChannelVideoInfo(mChannelList);
                } else {
                    mChannelListAdapter.appendChannelVideoInfo(mChannelList);
                }
            } else {
                if (mIsGrid) {
                    mChannelGridAdapter.setChannelVideoInfo(mChannelList);
                    showOppoGrid();
                } else {
                    mChannelListAdapter.setChannelVideoInfo(mChannelList);
                    showOppoList();
                }
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            MyLog.e(TAG, "error = " + error);
        }
    });
    jsObjRequest.setTag(TAG);
    jsObjRequest.setShouldCache(true);
    mQueue.add(jsObjRequest);
    mQueue.start();
}

  获取到JSON Object之后,就对这个JSONObject进行解析:

精彩图集

赞助商链接