时间:2021-07-01 10:21:17 帮助过:3人阅读
地址:http://music.163.com/api/playlist/detail?id=92664101
我想输出nickname和avatarUrl,循环输出歌单里歌的mp3Url,name还有artist里面的picUrl
如题,我想解析网易云音乐歌单内容,但是php不熟这段json又太复杂实在是没有解析出来...
地址:http://music.163.com/api/playlist/detail?id=92664101
我想输出nickname和avatarUrl,循环输出歌单里歌的mp3Url,name还有artist里面的picUrl
拿去玩吧。
演示地址:http://1.wxrain.sinaapp.com/sf-1010000004321535.php
不要跟我说时间怎么是几百秒的,自行转换
code != 200) {
exit('fetch data fail');
}
$result = $obj->result;
?>
netease JSON parse
creator->nickname;?>avatarUrl:creator->avatarUrl;?>
tracks)){?>
#
歌曲标题
时长
歌手
mp3Url
picUrl
tracks as $key=>$row){?>
name;?>
duration/1000;?>s
artists[0]->name;?>
mp3Url;?>" target="_blank">播放链接
album->picUrl;?>" target="_blank">picUrl
php 解析 json 使用 json_decode() 函数即可
http://www.php.com/manual/zh/function.json-decode.php
$json = json_decode(file_get_contens(http://music.163.com/api/playlist/detail?id=92664101),true);
echo $json['result']['creator']['nickname'];//fafatears
echo $json['result']['creator']['avatarUrl'];//http://p4.music.126.net/8H54LZSIvkMK8tqCJZnbTw==/3294136843838189.jpg
$mp3 = [];
$pic = [];
foreach($json['result']['tracks'] as $value){
$mp3[] = $value['mp3Url'];
foreach($value['artists'] as $v) {
$pic[] = $v['picUrl'];
}
}
var_dump($mp3);var_dump($pic);