0
我想从API iTunes Store获取数据到我的PHP文件。在搜索表单中,您可以填写歌曲的艺术家和标题。我只想显示歌曲中的数据。这是我的代码:iTunes搜索商店api
$title = $_POST["title"];
$artist = $_POST["artist"];
$query_string = urlencode($title);
$query_string2 = urlencode($artist);
$json = file_get_contents('https://itunes.apple.com/search?term=$query_string&term=$query_string2'); // this WILL do an http request for you
$data = json_decode($json);
echo "<div class='container' id='movies'>";
echo "<div class='col-md-4' id='movie'>";
echo "<img src='" .$data->artworkUrl60. "' width='200'>";
echo "<h4>" .$data->artistName. " - " .$data->trackName. "</h4>";
我得到这个错误:注意:未定义的属性:stdClass的:: $ artworkUrl60中.... 请告诉我错我的代码?
后续代码var_dump给所有的阵列。但是,当我这样做:。$ data-> artistName。我得到相同的错误 –
您应该添加一个foreach循环 –
它的工作原理,谢谢! –