-1

我从 iTunes API 获取 JSON 数据,但是当我 console.log 我的数据时,它说它未定义,我做错了什么吗?

jQuery

$(document).ready(function() {
    $.getJSON("http://itunes.apple.com/search?term=angry&limit=4&media=software&callback=?",function(data) {

        $.each(data, function(index, element) {
            console.log(element.artistName);
        });
    }); 
});

JSON

jQuery19108565351243602318_1364012908350(
{
 "resultCount":1,
 "results": [
{"kind":"software", "features":["gameCenter"], "supportedDevices":["iPad3G", "iPodTouchourthGen", "iPhone-3GS", "iPodTouchThirdGen", "iPad23G", "iPhone4", "iPadWifi", "iPad2Wifi"], "isGameCenterEnabled":true, 
"screenshotUrls":["http://a786.phobos.apple.com/us/r1000/069/Purple2/v4/61/c6/55/61c655ac-5c32-c9d6-61c1-d4025c5822ed/mzl.babhynjf.png", "http://a1425.phobos.apple.com/us/r1000/061/Purple/v4/c1/f3/51/c1f35156-fc04-bd31-bb92-b695043e922c/mzl.vzvfrzpz.png", "http://a712.phobos.apple.com/us/r1000/068/Purple2/v4/ea/40/5a/ea405a80-c31d-6061-cc7c-3f88d4d80659/mzl.zmdognad.png", "http://a1974.phobos.apple.com/us/r1000/063/Purple/v4/c1/b1/53/c1b153df-3657-1b84-350d-257201dab7b2/mzl.qwyhrzas.png", "http://a294.phobos.apple.com/us/r1000/061/Purple2/v4/c2/b0/d2/c2b0d22c-a3fe-0afc-8766-3def3d3bac57/mzl.szsfyhqo.png"], "ipadScreenshotUrls":[], "artworkUrl60":"http://a1102.phobos.apple.com/us/r1000/061/Purple2/v4/49/b6/7d/49b67d81-a95a-bbee-fc02-486f8ee174d8/Icon.png", "artworkUrl512":"http://a141.phobos.apple.com/us/r1000/105/Purple2/v4/9a/2a/1e/9a2a1e43-fbd5-32d7-53c7-9490d77ce891/mzl.wepjpyjw.png", "artistViewUrl":"https://itunes.apple.com/us/artist/rovio-entertainment-ltd/id298910979?uo=4", "artistId":298910979, "artistName":"Rovio Entertainment Ltd", "price":0.99, "version":"3.1.0", 
"description":"Use the unique powers of the Angry Birds to destroy the greedy pigs' defenses!\u2028\u2028\n\nThe survival of the Angry Birds is at stake. Dish out revenge on the greedy pigs who stole their eggs. Use the unique powers of each bird to destroy the pigs\u2019 defenses. Angry Birds features challenging physics-based gameplay and hours of replay value. Each level requires logic, skill and force to solve.\u2028\u2028\n\nIf you get stuck in the game, you can purchase the Mighty Eagle! Mighty Eagle is a one-time in-app purchase in Angry Birds that gives unlimited use. This phenomenal creature will soar from the skies to wreak havoc and smash the pesky pigs into oblivion. There\u2019s just one catch: you can only use the aid of Mighty Eagle to pass a level once per hour. Mighty Eagle also includes all new gameplay goals and achievements!\u2028\u2028\n\nIn addition to the Mighty Eagle, Angry Birds now has power-ups! Boost your birds\u2019 abilities and three-star levels to unlock secret content! Angry Birds now has the following amazing power-ups: Sling Scope for laser targeting, King Sling for maximum flinging power, Super Seeds to supersize your birds, and Birdquake to shake pigs\u2019 defenses to the ground!\u2028\u2028\n\n#1 IPHONE PAID APP in US, UK, Canada, Italy, Germany, Russia, Sweden, Denmark, Finland, Singapore, Poland, France, Netherlands, Malta, Greece, Austria, Australia, Turkey, UAE, Saudi Arabia, Israel, Belgium, Norway, Hungary, Malaysia, Luxembourg, Portugal, Czech Republic, Spain, Ireland, Romania, New Zealand, Latvia, Lithuania, Estonia, Nicaragua, Kazakhstan, Argentina, Bulgaria, Slovakia, Slovenia, Mauritius, Chile, Hong Kong, Pakistan, Taiwan, Colombia, Indonesia, Thailand, India, Kenya, Macedonia, Croatia, Macau, Paraguay, Peru, Armenia, Philippines, Vietnam, Jordan and Kuwait. \u2028\u2028\n\nNote: if you are having a problem with your device crashing after installing the update, try shutting down and restarting the device. If you are still having problems, contact support@rovio.com.\n\n#1 IPHONE PAID GAME in more countries than we can count!\n\nTerms of Use: http://www.rovio.com/eula\u2028\nPrivacy Policy: http://www.rovio.com/privacy\u2028\n\nThis application may require internet connectivity and subsequent data transfer charges may apply.", "currency":"USD", "genres":["Games", "Entertainment", "Action", "Arcade"], "genreIds":["6014", "6016", "7001", "7003"], "releaseDate":"2009-12-11T08:00:00Z", "sellerName":"Rovio Entertainment Ltd", "bundleId":"com.clickgamer.AngryBirds", "trackId":343200656, "trackName":"Angry Birds", "primaryGenreName":"Games", "primaryGenreId":6014, "releaseNotes":"Check out 15 fantastic new levels for the Bad Piggies episode! OINK!", "formattedPrice":"$0.99", "wrapperType":"software", "trackCensoredName":"Angry Birds", "languageCodesISO2A":["EN"], "fileSizeBytes":"35746968", "sellerUrl":"http://www.angrybirds.com/", "contentAdvisoryRating":"4+", "averageUserRatingForCurrentVersion":4.5, "userRatingCountForCurrentVersion":1302, "artworkUrl100":"http://a141.phobos.apple.com/us/r1000/105/Purple2/v4/9a/2a/1e/9a2a1e43-fbd5-32d7-53c7-9490d77ce891/mzl.wepjpyjw.png", "trackViewUrl":"https://itunes.apple.com/us/app/angry-birds/id343200656?mt=8&uo=4", "trackContentRating":"4+", "averageUserRating":4.5, "userRatingCount":821819}]
}
);
4

1 回答 1

2

它应该是

$.each(data.results, function(index, element) {
    console.log(element.artistName);
});

data是一个有两个属性resultCount和的对象results,实际的数据数组存储在 中results,所以你需要遍历data.results而不是data

于 2013-03-23T04:40:44.773 回答