我正在尝试从此 API 中提取信息:http://ex.fm/api/v3/user/dan/loved
我在使用 Google Maps API 之前就已完成此操作,但那是使用 simplexml_load_file
。我尝试将相同的脚本应用于此 API,但它就是不喜欢它。
所以我有点不知道从哪里开始。本质上,我试图获取每个项目的图像源并显示它。
最佳答案
我认为你需要看看这里:PHP JSON 。
$contents = file_get_contents("http://ex.fm/api/v3/user/dan/loved");
$contents = json_decode($contents);
// in order to display images
foreach ($contents->songs as $song) {
printf("Image Small: %s\n", $song->image->small);
printf("Image Large: %s\n", $song->image->large);
// ...
}
// in order to store song attributes
/* $songs = array();
foreach ($contents->songs as $song) {
$songs[] = array(
'title' => $song->title,
'image_small' => $song->image->small,
// add more stuff...
);
} */
输出看起来像;
Image Small: http://userserve-ak.last.fm/serve/34/59939953.png Image Large: http://userserve-ak.last.fm/serve/126/59939953.png Image Small: http://www.blogcdn.com/www.spinner.com/media/2013/02/thao-with-the-get-down-stay-down-320.jpg Image Large: http://www.blogcdn.com/www.spinner.com/media/2013/02/thao-with-the-get-down-stay-down-320.jpg Image Small: http://24.media.tumblr.com/tumblr_mhpvhhmZbD1qz4e0mo1_1360016551_cover.jpg Image Large: http://24.media.tumblr.com/tumblr_mhpvhhmZbD1qz4e0mo1_1360016551_cover.jpg ...
关于php - 从 API 检索信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14945384/