gpt4 book ai didi

Javascript omdb api不会发送所有信息

转载 作者:行者123 更新时间:2023-11-29 23:52:41 24 4
gpt4 key购买 nike

我的问题是我每次搜索只能得到一部电影。例如,如果我搜索“哈利波特”,我希望能够获取所有哈利波特电影 JSON 对象。目前我在搜索哈利波特时只能找到哈利波特和死亡圣器。

$("#btnSearch").on("click", function(){
var input = $("#search").val();
$(".search-result").find("h3").show();
$(".search-result").find("h3").text("Laddar...");
$.ajax({
url: "http://www.omdbapi.com/?t="+input+"&y=&plot=short&r=json",
dataType: "JSON"
}).done(function(data){
var movie = data.Title;
var year = data.Year;
$(".search-result").find("h3").text(movie+"("+year+")");
$(".search-result").find("h3").show();
}).fail(function(data){
$(".search-result").find("h3").text("Något gick fel...");
$(".search-result").find("h3").show();
});
});

最佳答案

来自 OMDB Api documentation ,您正在使用 t 参数执行搜索 By Title

您想使用 s 参数请求 By Search :

http://www.omdbapi.com/?s=Harry+Potter&y=&plot=short&r=json

它给你一个包含所有匹配数据的数组:

{
"Search": [{
"Title": "Harry Potter and the Deathly Hallows: Part 2",
"Year": "2011",
"imdbID": "tt1201607",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BMTY2MTk3MDQ1N15BMl5BanBnXkFtZTcwMzI4NzA2NQ@@._V1_SX300.jpg"
}, {
"Title": "Harry Potter and the Sorcerer's Stone",
"Year": "2001",
"imdbID": "tt0241527",
"Type": "movie",
"Poster": "https://images-na.ssl-images-amazon.com/images/M/MV5BNjQ3NWNlNmQtMTE5ZS00MDdmLTlkZjUtZTBlM2UxMGFiMTU3XkEyXkFqcGdeQXVyNjUwNzk3NDc@._V1_SX300.jpg"
},
.......
.......
.......
{
"Title": "Harry Potter and the Order of the Phoenix",
"Year": "2007",
"imdbID": "tt0944836",
"Type": "game",
"Poster": "http://ia.media-imdb.com/images/M/MV5BN2VhOGI0OTItZjVhMC00MThmLWI5YzEtYTk5ZTFhMjEzOGEzXkEyXkFqcGdeQXVyNzg5OTk2OA@@._V1_SX300.jpg"
}],
"totalResults": "77",
"Response": "True"
}

您可以使用以下方法获取标题:

$.ajax({
url: "http://www.omdbapi.com/?s=Harry+Potter&y=&plot=short&r=json",
dataType: "JSON"
}).done(function(data) {
var search = data.Search;
for (movie in search) {
console.log("title : " + search[movie].Title);
}
}).fail(function(data) {
console.log("fail");
});

关于Javascript omdb api不会发送所有信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42471877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com