求高手這段json怎樣用php解析

來源:互聯網
上載者:User
如題,我想解析網易雲音樂歌單內容,但是php不熟這段json又太複雜實在是沒有解析出來...

地址: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)){?> tracks as $key=>$row){?>
# 歌曲標題 時間長度 歌手 mp3Url picUrl
name;?> duration/1000;?>s artists[0]->name;?> mp3Url;?>" target="_blank">播放連結 album->picUrl;?>" target="_blank">picUrl

php 解析 json 使用 json_decode() 函數即可

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);
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.