使用php从JSON中解析数组中的数据

时间:2014-10-15 16:56:42

标签: php json

{"type":"result","data":[{"title":"Web Radio \u0391\u03a5\u039b\u0391\u0399\u0391","song":"ELENI XATZIDOU - DEN 8A SE PERIMENW","track":{"artist":"ELENI XATZIDOU","title":"DEN 8A SE PERIMENW","album":"WEB RADIO AYLAIA","royaltytrackid":7385.0000,"id":7385,"playlist":{"id":133,"title":"03.Tetarti"},"buyurl":"","imageurl":"http:\/\/188.40.166.136:2197\/static\/ilias\/covers\/rsz_emb_eleni_xatzidou_den_8a_se_perimenw_eeec1cadjpg"},"bitrate":"192 Kbps","server":"Online","autodj":"Online","source":"Yes","offline":false,"summary":"<a href=\"http:\/\/188.40.166.136:2199\/tunein\/-stream\/ilias.pls\">Web Radio \u0391\u03a5\u039b\u0391\u0399\u0391 - ELENI XATZIDOU - DEN 8A SE PERIMENW<\/a>","listeners":1,"maxlisteners":150,"reseller":0,"serverstate":true,"sourcestate":true,"sourceconn":true,"date":"Oct 15, 2014","time":"06:51 PM","rawmeta":"ELENI XATZIDOU - DEN 8A SE PERIMENW ","url":"http:\/\/188.40.166.136:2199\/rpc"}]}

我有上面的JSON文件,我想获得歌曲标题(&#34; ELENI XATZIDOU - DEN 8A SE PERIMENW&#34;)。我想用php做。我是JSON的新手,我认为这对你们中的一些人来说不是很苛刻。

提前谢谢!

2 个答案:

答案 0 :(得分:3)

$stdObj = json_decode($json);
echo $stdObj->data[0]->song;

$data = json_decode($json, true);
echo $data['data'][0]['song'];

答案 1 :(得分:1)

<?php
$data = '{"type":"result","data":[{"title":"Web Radio \u0391\u03a5\u039b\u0391\u0399\u0391","song":"ELENI XATZIDOU - DEN 8A SE PERIMENW","track":{"artist":"ELENI XATZIDOU","title":"DEN 8A SE PERIMENW","album":"WEB RADIO AYLAIA","royaltytrackid":7385.0000,"id":7385,"playlist":{"id":133,"title":"03.Tetarti"},"buyurl":"","imageurl":"http:\/\/188.40.166.136:2197\/static\/ilias\/covers\/rsz_emb_eleni_xatzidou_den_8a_se_perimenw_eeec1cadjpg"},"bitrate":"192 Kbps","server":"Online","autodj":"Online","source":"Yes","offline":false,"summary":"<a href=\"http:\/\/188.40.166.136:2199\/tunein\/-stream\/ilias.pls\">Web Radio \u0391\u03a5\u039b\u0391\u0399\u0391 - ELENI XATZIDOU - DEN 8A SE PERIMENW<\/a>","listeners":1,"maxlisteners":150,"reseller":0,"serverstate":true,"sourcestate":true,"sourceconn":true,"date":"Oct 15, 2014","time":"06:51 PM","rawmeta":"ELENI XATZIDOU - DEN 8A SE PERIMENW ","url":"http:\/\/188.40.166.136:2199\/rpc"}]}';


$json_decode = json_decode($data);

echo $json_decode->data[0]->song;

?>