2015-06-28 29 views
0

我想從http://omadbapi.com/?s=搜索腳本GET JSON,但我有與此JSON獲得標題元素麻煩:如何訪問Json中的元素標題?

{ 
    "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; 
      }); 
     }); 
    }); 
}); 

我怎樣才能找回p.Titledata.Title從返回的JSON?

回答

0

嘗試這樣

$.each(data.Search, function(e,p) { 
    document.getElementById("item").innerHTML="Title : " + p.Title; 
});