Ask the Master this JSON how to use PHP parsing

Source: Internet
Author: User
Tags php foreach
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)) {?> Tracks as $key = $row) {?>
# Song title Length of Time singer Mp3url Picurl
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);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.