Q:

drill down through json data

Im experimenting with the espn public API and am trying to use their json to access NFL player information.
the json im accessing succesfully looks like:
{
"sports": [
    {
        "name": "football",
        "id": 20,
        "leagues": [
            {
                "name": "National Football League",
                "abbreviation": "nfl",
                "id": 28,
                "groupId": 9,
                "shortName": "NFL",
                "athletes": [
                    {
                        "id": 14466,
                        "firstName": "Isa",
                        "lastName": "Abdul-Quddus",
                        "fullName": "Isa Abdul-Quddus",
                        "displayName": "Isa Abdul-Quddus",
                        "shortName": "I. Abdul-Quddus",
                        "links": {
                            "api": {
                                "athletes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/14466"
                                },
                                "news": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/14466/news"
                                },
                                "notes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/14466/news/notes"
                                }
                            },
                            "web": {
                                "athletes": {
                                    "href": "http://espn.go.com/nfl/player/_/id/14466/isa-abdul-quddus?ex_cid=espnapi_public"
                                }
                            },
                            "mobile": {
                                "athletes": {
                                    "href": "http://m.espn.go.com/nfl/playercard?playerId=14466&ex_cid=espnapi_public"
                                }
                            }
                        }
                    },
                    {
                        "id": 8645,
                        "firstName": "Hamza",
                        "lastName": "Abdullah",
                        "fullName": "Hamza Abdullah",
                        "displayName": "Hamza Abdullah",
                        "shortName": "H. Abdullah",
                        "links": {
                            "api": {
                                "athletes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/8645"
                                },
                                "news": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/8645/news"
                                },
                                "notes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/8645/news/notes"
                                }
                            },
                            "web": {
                                "athletes": {
                                    "href": "http://espn.go.com/nfl/player/_/id/8645/hamza-abdullah?ex_cid=espnapi_public"
                                }
                            },
                            "mobile": {
                                "athletes": {
                                    "href": "http://m.espn.go.com/nfl/playercard?playerId=8645&ex_cid=espnapi_public"
                                }
                            }
                        }
                    },
                    {
                        "id": 11910,
                        "firstName": "Husain",
                        "lastName": "Abdullah",
                        "fullName": "Husain Abdullah",
                        "displayName": "Husain Abdullah",
                        "shortName": "H. Abdullah",
                        "links": {
                            "api": {
                                "athletes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/11910"
                                },
                                "news": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/11910/news"
                                },
                                "notes": {
                                    "href": "http://api.espn.com/v1/sports/football/nfl/athletes/11910/news/notes"
                                }
                            } ........
                ]
            }
        ]
    }
],
"resultsOffset": 0,
"resultsLimit": 50,
"resultsCount": 3301,
"timestamp": "2013-01-06T19:30:17Z",
"status": "success"

}
and heres the html / javascript Im using:
$(document).ready(function(){

    $.getJSON("http://api.espn.com/v1/sports/football/nfl/athletes?apikey=MY-API-KEY-HERE&_accept=application/json",
    function(data){
      $.each(data["sports"], function(i,item){
         $("#infoDiv").append( [i] + " - " + item.name + "<br>" );    
      });
    });

});
i can get this to display 0 - football   but cant use something like
$.each(data["sports"]["leagues"]["athletes"], function(i,item){
  $("#infoDiv").append( [i] + " - " + item.firstName + "<br>" );  

to access the individual athlete data such as item.firstName , etc.
i keep getting the following error:
TypeError: data.sports.leagues is undefined

what am I missing?   I'm using this same code structure successfully with a couple of other API's that provide json.   the ESPN json is a little more complex in comparison though.
thanks for any light you can shed on this for me.

A:

sports, leagues and athletes are arrays, for example: sports[0] is an object (the one with name='football')
You should iterate each like this (not tested):
$.each(data.sports, function(i,sport) {
    $.each(sport.leagues, function(i,league) {
        $.each(league.athletes, function(i,athlete) {
            $("#infoDiv").append( [i] + " - " + athlete.firstName + "<br>" );
        });
    });
});

