我找到了这个提供IMDB API的网站:http: //www.omdbapi.com
并且为了获得例如霍比特人,它很容易就这样:http://www.omdbapi.com/?i = ttt0903624
然后我得到所有这些信息:
{"Title":"The Hobbit: An Unexpected Journey","Year":"2012","Rated":"11","Released":"14 Dec 2012","Runtime":"2 h 46 min","Genre":"Adventure, Fantasy","Director":"Peter Jackson","Writer":"Fran Walsh, Philippa Boyens","Actors":"Martin Freeman, Ian McKellen, Richard Armitage, Andy Serkis","Plot":"A curious Hobbit, Bilbo Baggins, journeys to the Lonely Mountain with a vigorous group of Dwarves to reclaim a treasure stolen from them by the dragon Smaug.","Poster":"http://ia.media-imdb.com/images/M/MV5BMTkzMTUwMDAyMl5BMl5BanBnXkFtZTcwMDIwMTQ1OA@@._V1_SX300.jpg","imdbRating":"9.2","imdbVotes":"5,666","imdbID":"tt0903624","Response":"True"}
Run Code Online (Sandbox Code Playgroud)
问题是我只想要标题,年份和情节信息,我想知道我怎么才能找到这个.
我想用PHP.
在这里,您只需解码json,然后提取所需的数据.如果需要,您可以在之后将其重新编码为json.
$data = file_get_contents('http://www.omdbapi.com/?i=tt0903624');
$data = json_decode($data, true);
$data = array('Title' => $data['Title'], 'Plot' => $data['Plot']);
$data = json_encode($data);
print($data);
Run Code Online (Sandbox Code Playgroud)
另一种方法(稍微更有效)是取消设置不需要的键,例如:
$data = file_get_contents('http://www.omdbapi.com/?i=tt0903624');
$data = json_decode($data, true);
$keys = array_keys($data);
foreach ($keys as $key) {
if ($key != 'Title' && $key != 'Plot) {
unset($data[$key]);
}
}
$data = json_encode($data);
print($data);
Run Code Online (Sandbox Code Playgroud)