第二個ajax調用正在返回MoviesList
對象中的影片,因此您需要迭代data.MovieList
而不是data
。
JSON:
{
"MovieCount":4921,
"MovieList":
[{
"MovieID":"5372",
"State":"OK",
"MovieUrl":"https:\/\/yts.re\/movie\/Gun_Woman_2014_1080p",
"MovieTitle":"Gun Woman (2014) 1080p","MovieTitleClean":"Gun Woman",
"MovieYear":"2014",
"DateUploaded":"2014-06-30 00:10:03",
"DateUploadedEpoch":1404043803,
"Quality":"1080p",
"CoverImage":"https:\/\/static.yts.re\/attachments\/Gun_Woman_2014_1080p\/poster_med.jpg",
"ImdbCode":"tt3141912",
"ImdbLink":"http:\/\/www.imdb.com\/title\/tt3141912\/",
"Size":"1.24 GB",
"SizeByte":"1335275815",
"MovieRating":"8.2",
"Genre":"Action",
"Uploader":"OTTO",
"UploaderUID":"310615",
"Downloaded":"35173",
"TorrentSeeds":"20",
"TorrentPeers":"24497",
"TorrentUrl":"https:\/\/yts.re\/download\/start\/777FD07DAD285CB06846CAFD97600B07F2CC88B3.torrent",
"TorrentHash":"777fd07dad285cb06846cafd97600b07f2cc88b3",
"TorrentMagnetUrl":"magnet:?xt=urn:btih:777fd07dad285cb06846cafd97600b07f2cc88b3&dn=Gun+Woman&tr=http:\/\/exodus.desync.com:6969\/announce&tr=udp:\/\/tracker.openbittorrent.com:80\/announce&tr=udp:\/\/open.demonii.com:1337\/announce&tr=udp:\/\/exodus.desync.com:6969\/announce&tr=udp:\/\/tracker.yify-torrents.com\/announce"
}]
}
這樣做:
$.getJSON("https://yts.re/api/list.json", function (data) {
console.log("Getting all the movies");
// console.log(data)
$.each(data.MovieList, function (item, value) {
console.log(value.MovieTitleClean + ' ' + value.ImdbLink);
});
});
UPDATED FIDDLE
因爲它返回不同的JSON –