The code is as follows:
<code><?php $url = 'http://music.163.com/api/song/detail/?id='.$_GET['id'].'&ids=%5B'.$_GET['id'].'%5D&csrf_token='; $json = file_get_contents($url); $obj = json_decode($json); $array = array( "name" => $obj->songs[0]->bMusic->name, "artist" => $obj->songs[0]->artists[0]->name, "url" => $obj->songs[0]->mp3Url ); echo json_encode($array); ?> </code>
The json file is roughly like this:
<code>{ "songs": [ { "starred": false, "popularity": 95, "starredNum": 0, "playedNum": 0, "dayPlays": 0, "hearTime": 0, "mp3Url": "http://m2.music.126.net/2b980AHtVx18bJ_Z9MhKXA==/2830142929914115.mp3", "rtUrls": [], "status": 1, "crbt": null, "bMusic": { "volumeDelta": 0.095421, "playTime": 200000, "bitrate": 96000, "dfsId": 2830142929914115, "sr": 44100, "name": "Set Fire To The Rain", "id": 24667967, "size": 2436177, "extension": "mp3" }, "rtUrl": null, "position": 2, "duration": 200000, "alias": [], "hMusic": { "volumeDelta": -0.05, "playTime": 200000, "bitrate": 320000, "dfsId": 2830142929914113, "sr": 44100, "name": "Set Fire To The Rain", "id": 24667965, "size": 8056892, "extension": "mp3" }, "mMusic": { "volumeDelta": 0.41, "playTime": 200000, "bitrate": 160000, "dfsId": 2830142929914114, "sr": 44100, "name": "Set Fire To The Rain", "id": 24667966, "size": 4042394, "extension": "mp3" }, "lMusic": { "volumeDelta": 0.095421, "playTime": 200000, "bitrate": 96000, "dfsId": 2830142929914115, "sr": 44100, "name": "Set Fire To The Rain", "id": 24667967, "size": 2436177, "extension": "mp3" }, "album": { "songs": [], "paid": false, "onSale": false, "status": 1, "tags": "", "blurPicUrl": "http://p4.music.126.net/J32cgj_Dq-4Wpfs4U9sjwA==/2539871860943087.jpg", "companyId": 0, "pic": 2539871860943087, "description": "", "subType": null, "alias": [], "picId": 2539871860943087, "briefDesc": "", "artist": { "img1v1Id": 0, "alias": [], "picId": 0, "briefDesc": "", "picUrl": "http://p4.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "albumSize": 0, "img1v1Url": "http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "trans": "", "musicSize": 0, "name": "", "id": 0 }, "picUrl": "http://p4.music.126.net/J32cgj_Dq-4Wpfs4U9sjwA==/2539871860943087.jpg", "commentThreadId": "R_AL_3_1983765", "artists": [ { "img1v1Id": 0, "alias": [], "picId": 0, "briefDesc": "", "picUrl": "http://p4.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "albumSize": 0, "img1v1Url": "http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "trans": "", "musicSize": 0, "name": "Piano Tribute Players", "id": 99094 } ], "copyrightId": 0, "publishTime": 1321804800000, "company": "CC Entertainment", "name": "Piano Tribute to Adele", "id": 1983765, "type": "专辑", "size": 14 }, "commentThreadId": "R_SO_4_21515271", "artists": [ { "img1v1Id": 0, "alias": [], "picId": 0, "briefDesc": "", "picUrl": "http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "albumSize": 0, "img1v1Url": "http://p4.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "trans": "", "musicSize": 0, "name": "Piano Tribute Players", "id": 99094 } ], "copyrightId": 0, "score": 95, "fee": 0, "mvid": 0, "ftype": 0, "rtype": 0, "rurl": null, "copyFrom": "", "audition": null, "ringtone": "", "disc": "", "no": 2, "name": "Set Fire To The Rain", "id": 21515271 } ], "equalizers": {}, "code": 200 }</code>
Upload to host page output result:
Notice: Trying to get property of non-object in on line 6 {"name":null,"artist":"Piano Tribute Players","url":null}
Reply content:
The code is as follows:
<code><?php $url = 'http://music.163.com/api/song/detail/?id='.$_GET['id'].'&ids=%5B'.$_GET['id'].'%5D&csrf_token='; $json = file_get_contents($url); $obj = json_decode($json); $array = array( "name" => $obj->songs[0]->bMusic->name, "artist" => $obj->songs[0]->artists[0]->name, "url" => $obj->songs[0]->mp3Url ); echo json_encode($array); ?> </code>
The json file is roughly like this:
<code>{ "songs": [ { "starred": false, "popularity": 95, "starredNum": 0, "playedNum": 0, "dayPlays": 0, "hearTime": 0, "mp3Url": "http://m2.music.126.net/2b980AHtVx18bJ_Z9MhKXA==/2830142929914115.mp3", "rtUrls": [], "status": 1, "crbt": null, "bMusic": { "volumeDelta": 0.095421, "playTime": 200000, "bitrate": 96000, "dfsId": 2830142929914115, "sr": 44100, "name": "Set Fire To The Rain", "id": 24667967, "size": 2436177, "extension": "mp3" }, "rtUrl": null, "position": 2, "duration": 200000, "alias": [], "hMusic": { "volumeDelta": -0.05, "playTime": 200000, "bitrate": 320000, "dfsId": 2830142929914113, "sr": 44100, "name": "Set Fire To The Rain", "id": 24667965, "size": 8056892, "extension": "mp3" }, "mMusic": { "volumeDelta": 0.41, "playTime": 200000, "bitrate": 160000, "dfsId": 2830142929914114, "sr": 44100, "name": "Set Fire To The Rain", "id": 24667966, "size": 4042394, "extension": "mp3" }, "lMusic": { "volumeDelta": 0.095421, "playTime": 200000, "bitrate": 96000, "dfsId": 2830142929914115, "sr": 44100, "name": "Set Fire To The Rain", "id": 24667967, "size": 2436177, "extension": "mp3" }, "album": { "songs": [], "paid": false, "onSale": false, "status": 1, "tags": "", "blurPicUrl": "http://p4.music.126.net/J32cgj_Dq-4Wpfs4U9sjwA==/2539871860943087.jpg", "companyId": 0, "pic": 2539871860943087, "description": "", "subType": null, "alias": [], "picId": 2539871860943087, "briefDesc": "", "artist": { "img1v1Id": 0, "alias": [], "picId": 0, "briefDesc": "", "picUrl": "http://p4.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "albumSize": 0, "img1v1Url": "http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "trans": "", "musicSize": 0, "name": "", "id": 0 }, "picUrl": "http://p4.music.126.net/J32cgj_Dq-4Wpfs4U9sjwA==/2539871860943087.jpg", "commentThreadId": "R_AL_3_1983765", "artists": [ { "img1v1Id": 0, "alias": [], "picId": 0, "briefDesc": "", "picUrl": "http://p4.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "albumSize": 0, "img1v1Url": "http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "trans": "", "musicSize": 0, "name": "Piano Tribute Players", "id": 99094 } ], "copyrightId": 0, "publishTime": 1321804800000, "company": "CC Entertainment", "name": "Piano Tribute to Adele", "id": 1983765, "type": "专辑", "size": 14 }, "commentThreadId": "R_SO_4_21515271", "artists": [ { "img1v1Id": 0, "alias": [], "picId": 0, "briefDesc": "", "picUrl": "http://p3.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "albumSize": 0, "img1v1Url": "http://p4.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg", "trans": "", "musicSize": 0, "name": "Piano Tribute Players", "id": 99094 } ], "copyrightId": 0, "score": 95, "fee": 0, "mvid": 0, "ftype": 0, "rtype": 0, "rurl": null, "copyFrom": "", "audition": null, "ringtone": "", "disc": "", "no": 2, "name": "Set Fire To The Rain", "id": 21515271 } ], "equalizers": {}, "code": 200 }</code>
Upload to host page output result:
Notice: Trying to get property of non-object in on line 6 {"name":null,"artist":"Piano Tribute Players","url":null}
json also has two commands:
json_last_error_msg This is to get the error message of json.
json_last_error returns the last error that occurred
You can try using these two commands to see what errors occurred in json_encode.
I remember seeing something written like this in the PHP official website manual:
<code>$obj->{$music->name}</code>
This kind of thing, I don’t know if it has anything to do with it...
(I usually use arrays in similar scenarios, and I feel it’s easier to use than objects in php... I’m sorry for the newbies~)

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
