对比分析json及XML(10)


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进行解析:

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgswyx.html