2014-06-29 125 views
0

我最近遇到了Yasty-torrent的api,地址爲YifyTorrentAPI,我們只是想讓我們試試jQuery並創建一個自己的應用程序。我用下面的代碼來檢索工作的upcomming電影列表。Yify torrent api返回undefined值

$.getJSON("https://yts.re/api/upcoming.json", function(data) { 

        $.each(data, function(item, value) { 
         console.log(value.MovieTitle + ' ' + value.ImdbLink); 
        }); 

       }); 
另一邊

當我試着用下面的請求我剛剛在控制檯中未定義讓所有的電影名單。

$.getJSON("https://yts.re/api/list.json", function (data) { 
        $.each(data, function (item, value) { 
         console.log(value.MovieTitleClean + ' ' + value.ImdbLink); 
        }); 

       }); 

我在分享我在其中編寫代碼的Fiddle。任何幫助將不勝感激。謝謝

+0

因爲它返回不同的JSON –

回答

1

第二個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

+0

謝謝伊赫桑。它確實有效! :-) –

+1

welcom @JamalHussain很高興幫助 –