【发布时间】:2016-04-27 02:55:45
【问题描述】:
如何将 Itunes 热门专辑名称、艺术家姓名和 ID JSON 转换为 PHP。
https://itunes.apple.com/us/rss/topalbums/limit=10/json
我尝试了类似的东西
<?php
$content=file_get_contents("https://itunes.apple.com/us/rss/topalbums/limit=10/json");
$top_albums=json_decode($content);
$tracks = $top_albums->feed->entry;
foreach( $tracks as $track ) {
$name = $track->title->lable;
echo $name. "<br/>";
}
?>
Notice: Undefined property: stdClass::$lable in C:\xampp\htdocs\test\itunes.php on line 6
需要工作代码才能从 feed-> 条目中获取所有专辑,例如 im:name im:artist im:image title。
【问题讨论】:
-
你能
print_r($top_albums)看看它有什么吗? -
是的,它输出数组,如 stdClass 对象 ( [feed] => stdClass Object ( [author] => stdClass Object ( [name] => stdClass Object ( [label] => iTunes Store ) [uri ] => stdClass Object ( [label] => apple.com/itunes ) ) [entry] => Array ( [0] => stdClass Object ( [im:name] => stdClass Object ( [label] => The Very Best of王子)
-
你能在
print_r($track)循环中foreach -
是的,例如 stdClass 对象 ( [im:name] => stdClass 对象 ( [label] => The Very Best of Prince ) [im:image] => 数组 ( [0] => stdClass 对象( [标签] => is4.mzstatic.com/image/thumb/Music3/v4/aa/78/73/… [属性] => 标准类对象 ( [高度] => 55 ) )
-
尝试访问 $track->label 我认为它会起作用