求高手这段json怎样用php解析
如题,我想解析网易云音乐歌单内容,但是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><?php $url = 'http://music.163.com/api/playlist/detail?id=92664101'; $json = file_get_contents($url); $obj = json_decode($json); if (! is_object($obj) || $obj->code != 200) { exit('fetch data fail'); } $result = $obj->result; ?> <meta charset="UTF-8"> <title>netease JSON parse</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <link href="http://www.bootcss.com/p/flat-ui/css/flat-ui.css" rel="stylesheet"> <link rel="shortcut icon" href="http://a.tbcdn.cn/s/kissy/favicon.ico" type="image/x-icon"> <div class="container"> <h1 class="page-header"> <?php echo $result->creator->nickname;?><small>avatarUrl:<?php echo $result->creator->avatarUrl;?></small> </h1> <div class="row"> <?php if(count($result->tracks)){?> <table class="table table-striped"> <thead> <tr> <th>#</th> <th>歌曲标题</th> <th>时长</th> <th>歌手</th> <th>mp3Url</th> <th>picUrl</th> </tr> </thead> <tbody> <?php foreach($result->tracks as $key=>$row){?> <tr> <th><?php echo $key;?></th> <th> <?php echo $row->name;?></th> <th> <?php echo $row->duration/1000;?>s</th> <th> <?php echo $row->artists[0]->name;?></th> <th><a href="<?php%20echo%20%24row->mp3Url;?>" target="_blank">播放链接</a></th> <th><a href="<?php%20echo%20%24row->album->picUrl;?>" target="_blank">picUrl</a></th> </tr> <?php }?> </tbody> </table> <?php }?> </div> </div> </code>
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'];//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);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,
