如何使用 volley 库访问 JsonArray 中的值

how to access a value in JsonArray with volley library

我的问题是我找不到访问 JSON object.

中的值的方法

这是我的格式 JSON:

 [
    {
        "title": "Foot - ANG - Eden Hazard (Chelsea) élu joueur de l'année de Premier League !",
        "link": "http://www.lequipe.fr/Football/Actualites/Eden-hazard-chelsea-elu-joueur-de-l-annee-de-premier-league/554292#xtor=RSS-1",
        "description": "Comme attendu, Eden Hazard a été élu ce dimanche joueur de l'année de... ",
        "pubDate": "Mon, 27 Apr 2015 00:20:00 +0200",
        "enclosure": {
            "@attributes": {
                "url": "http://medias.lequipe.fr/img-photo-jpg/football-chelsea-v-stoke-city-barclays-premier-league-stamford-bridge-4-4-15-eden-hazard-cel/1500000000558260/0:91,2048:1123-665-335-70/94bd6.jpg",
                "length": "50000",
                "type": "image/jpeg"
            }
        }
    }

这是使用 Volley 库的代码。我可以得到标题,但我无法得到 attributes object 下 enclosure object.

下的 url 值
for (int i = 0; i < response.length(); i++)
                            try {

                                JSONObject obj = response.getJSONObject(i);
                                New aNew = new New();
                                aNew.setTitle(obj.getString("title"));
                                // Genre is json array
                                JSONObject enclosureObj = obj.getJSONObject("enclosure");
                                JSONObject attributesObj = enclosureObj.getJSONObject("attributes");

                                aNew.setImageURL(obj.getString("url"));
                                newList.add(aNew);
                                //Log.e("items", "item added !");
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

EXCEPTION 是:

04-26 23:46:12.752 11979-11979/customlistviewvolley.androidhive.info.customlistviewvolley E/json Exception﹕ org.json.JSONException: No value for attributes

好的,我解决了。

JSONObject enclosureObj = obj.getJSONObject("enclosure");
JSONObject attributesObj = enclosureObj.getJSONObject("@attributes");
aNew.setImageURL(obj.getString("url"));

我忘记了@attributes

中的@