For example, I want to parse the content of Netease cloud music songs, but php is not familiar with this json section. It is too complicated to parse it... Address: music.163.comapiplaylistdetail? Id92664101 I want to output nickname and avatarUrl, and cyclically output the mp3Url of the song in the song list ,... for example, I want to parse the content of the Netease cloud music song list, but php is not familiar with this json section and it is too complicated to parse it...
Http://music.163.com/api/playlist/detail? Id = 92664101
I want to output nickname and avatarUrl, cyclically output the mp3Url of the song in the song list, and the picUrl In the artist.
Reply content:
For example, I want to parse the content of the Netease cloud music song list, but php is not familiar with this json section and it is too complicated to parse it...
Http://music.163.com/api/playlist/detail? Id = 92664101
I want to output nickname and avatarUrl, cyclically output the mp3Url of the song in the song list, and the picUrl In the artist.
Take it for fun.
Demo address: http://1.wxrain.sinaapp.com/sf-1010000004321535.php
Don't tell me how the time is several hundred seconds, switch by yourself
Code! = 200) {exit ('fetch data fail ');} $ result = $ obj-> result;?>
Netease JSON parse
Creator-> nickname;?>AvatarUrl: Creator-> avatarUrl;?>
Tracks) {?>
# |
Song title |
Duration |
Artist |
Mp3Url |
PicUrl |
Tracks as $ key => $ row) {?>
|
Name;?> |
Duration/1000;?> S |
Artists [0]-> name;?> |
Mp3Url;?> "Target =" _ blank "> playback Link |
Album-> picUrl;?> "Target =" _ blank "> picUrl |
Use the json_decode () function to parse json in php.
Http://www.php.net/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'];//fafatearsecho $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);