Json数据的解析,获取其中的某个字段

阅读更多
在Json类返回的是一个array数组的情况下中使用:
Json json =new Json();
        try {
            JSONArray url = null;
            try {
                url = json.createJson();
            } catch (JSONException e) {
                e.printStackTrace();
            }
            Log.d(TAG,url + "onCreate()");
            Log.d(TAG,"url.length() = " + url.length());
            for(int i = 0; i < url.length(); i++){//遍历JSONArray

                Log.d(TAG,"debugTest" + Integer.toString(i));
                JSONObject oj = null;
                try {
                    oj = url.getJSONObject(Integer.parseInt(String.valueOf(i)));
                    Log.d(TAG,"oj" + oj);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                int aa = 0;
                try {
                    aa = oj.getInt("url");
                    mDatas.add(aa);
                    Log.d(TAG,"aa" + aa);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                Log.d(TAG,aa + "");
            }
        }catch (Exception e){
            e.printStackTrace();
        }

你可能感兴趣的:(json,Android)