我想从http://omadbapi.com/?s=
获取JSON用于搜索脚本,但是我在这个JSON中遇到了获取Title元素的问题:
{
"Search": [{
"Title": "Sherlock Holmes: A Game of Shadows",
"Year": "2011",
"imdbID": "tt1515091",
"Type": "movie"
},{
"Title": "Spy Kids 3-D: Game Over",
"Year": "2003",
"imdbID": "tt0338459",
"Type": "movie"
}]
}
JavaScript:
$(document).ready(function () {
var url = 'http://www.omdbapi.com/?',
mode = 's=',
input,
movieName;
$('button').click(function() {
var input = $('#movie').val(),
movieName = encodeURI(input);
$.getJSON( url + mode + input, function( data ) {
$.each(data, function(e, p) {
document.getElementById("item").innerHTML="Title : " + p.Title;
});
});
});
});
如何从返回的JSON中检索p.Title
或data.Title
?
答案 0 :(得分:0)
试试这个
$.each(data.Search, function(e,p) {
document.getElementById("item").innerHTML="Title : " + p.Title;
});
答案 1 :(得分:0)