Title, I would like to analyze the NetEase Cloud music song single content, but PHP is not familiar with this JSON is too complex really is not parsed out ...
Address: http://music.163.com/api/playlist/detail?id=92664101
I want to output nickname and Avatarurl, loop out the songs in the song Mp3url,name and artist inside the Picurl
Reply content:
Title, I would like to analyze the NetEase Cloud music song single content, but PHP is not familiar with this JSON is too complex really is not parsed out ...
Address: http://music.163.com/api/playlist/detail?id=92664101
I want to output nickname and Avatarurl, loop out the songs in the song Mp3url,name and artist inside the Picurl
Take it to play.
Demo Address: http://1.wxrain.sinaapp.com/sf-1010000004321535.php
Don't tell me how the time is hundreds of seconds, self-conversion
Code! =) {exit (' fetch data fail ');} $result = $obj->result;? >
<title>NetEase JSON Parse</title>
Creator->nickname;? >avatarurl: creator->avatarurl;? >
Tracks)) {?>
# |
Song title |
Length of Time |
singer |
Mp3url |
Picurl |
Tracks as $key = $row) {?>
|
name;? > |
duration/1000;? >s |
artists[0]->name;? > |
mp3url;? > "target=" _blank "> Play link |
album->picurl;? > "target=" _blank ">picurl |
PHP parsing JSON uses the Json_decode () function to
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);