我找不到任何方法来解决以下问题。我的页面显示空白页。
我的代码
$s = '{"kind":"track","id":38140822,"created_at":"2012/02/28 19:52:55 +0000","user_id":10138280,"duration":206052,"commentable":true,"state":"finished","original_content_size":3297188,"last_modified":"2014/12/08 02:41:00 +0000","sharing":"public","tag_list":"","permalink":"jjefufcfzfdb","streamable":true,"embeddable_by":"all","downloadable":false,"purchase_url":null,"label_id":null,"purchase_title":null,"genre":"","title":"كيفك انت - فيروز","description":"غناء : فيروز \r\nكلمات : زياد الرحباني ","label_name":"","release":"","track_type":"","key_signature":"","isrc":"","video_url":null,"bpm":null,"release_year":null,"release_month":null,"release_day":null,"original_format":"mp3","license":"all-rights-reserved","uri":"https://api.soundcloud.com/tracks/38140822","user":{"id":10138280,"kind":"user","permalink":"ajassim","username":"Aj Assim","last_modified":"2014/12/03 11:21:20 +0000","uri":"https://api.soundcloud.com/users/10138280","permalink_url":"http://soundcloud.com/ajassim","avatar_url":"https://i1.sndcdn.com/avatars-000037250069-f7k40a-large.jpg"},"permalink_url":"http://soundcloud.com/ajassim/jjefufcfzfdb","artwork_url":"https://i1.sndcdn.com/artworks-000019131565-k8e2j1-large.jpg","waveform_url":"https://w1.sndcdn.com/HfpRLxTHxxOK_m.png","stream_url":"https://api.soundcloud.com/tracks/38140822/stream","playback_count":3438477,"download_count":100,"favoritings_count":82285,"comment_count":3027,"attachments_uri":"https://api.soundcloud.com/tracks/38140822/attachments","policy":"ALLOW"}';
$simplexml = simplexml_load_string($s);
var_dump($simplexml); //returns the actual structure
使用以下行
启用错误报告后error_reporting(E_ALL);
我收到了这些错误
Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /code/b2ET3r on line 4
Warning: simplexml_load_string(): {"kind":"track","id":38140822,"created_at":"2012/02/28 19:52:55 +0000","user_id" in /code/b2ET3r on line 4
Warning: simplexml_load_string(): ^ in /code/b2ET3r on line 4
bool(false) PHP Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /code/b2ET3r on line 4 PHP Warning: simplexml_load_string(): {"kind":"track","id":38140822,"created_at":"2012/02/28 19:52:55 +0000","user_id" in /code/b2ET3r on line 4 PHP Warning: simplexml_load_string(): ^ in /code/b2ET3r on line 4
答案 0 :(得分:3)
为什么要尝试使用simplexml解析Json?
尝试json_decode
$array = json_decode($s, true);
http://php.net/manual/en/function.json-decode.php
获得头衔
$array = json_decode($s, true);
echo $array['title'];
或
$object = json_decode($s, false);
echo $object->title;