我最近在YifyTorrentAPI遇到了Yify-torrents api,只是想让我们试一试jquery并创建一个自己的应用程序。 我使用以下代码来检索有效的upcomming电影列表。
$.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); }); });我正在分享我编写代码的小提琴 。 任何帮助将不胜感激。 谢谢
I recently came across the Yify-torrents api at YifyTorrentAPI and just thought let's give it a try with jquery and create a little own application. I used the following code to retrieve the upcomming movies list which worked.
$.getJSON("https://yts.re/api/upcoming.json", function(data) { $.each(data, function(item, value) { console.log(value.MovieTitle + ' ' + value.ImdbLink); }); });on the other side when I tried to get all the movies list using the following request I just got undefined in the console.
$.getJSON("https://yts.re/api/list.json", function (data) { $.each(data, function (item, value) { console.log(value.MovieTitleClean + ' ' + value.ImdbLink); }); });I am sharing the Fiddle in which I have wrote the code. Any help will be appreciated. Thanks
最满意答案
第二个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); }); });更新的FIDDLE
The second ajax call is returning movies in a MoviesList object so you need to iterate on data.MovieList not 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" }] }do like this:
$.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
更多推荐
发布评论