[英]decode json syntax with php
我的json_decode有问题。 我在以下json中找不到正确的语法来检索标题:
{
"name": "Emission",
"count": 18,
"lastsuccess": "Thu Apr 03 2014 09:03:36 GMT+0000 (UTC)",
"results": {
"Bourdin Direct": [
{
"Titre": {
"href": "http://www.channel.com/video/",
"text": "The TV SHOW"
},
"Date": "31/03/2014",
"Duree": {
"href": "http://www.channel.com/187457/",
"text": "19:06"
},
},
{
"Titre": {
"href": "http://www.channel.com/video/theshow/",
"text": "The title"
},
"Date": "28/03/2014",
"Duree": {
"href": "http://www.channel.com/video/28-03-186929/",
"text": "19:42"
},
}
]
}
}
现在,我有:
$json = file_get_contents($url);
$data = json_decode($json);
foreach ($data->results as $aArticle) {
$titre = $aArticle->Titre;
}
你有什么主意吗 ? 谢谢 !
您的“结果”数据格式不正确。
尝试这种格式,它正在工作
{“名称”:“排放”,“计数”:18,“最后成功”:“ 2014年4月3日星期四09:03:36 GMT + 0000(UTC)”,“结果”:{“ Bourdin Direct”:[{“ Titre“:{” href“:[” http://www.channel.com/video/“],” text“:[” TV SHOW“]},” Date“:[” 2014年3月3日“ ]},{“ Titre”:{“ href”:[“ http://www.channel.com/video/”],“ text”:[“ The TV SHOW”]},“ Date”:[“ 31 / 03/2014“]}]}}
$json = file_get_contents($url);
$data = json_decode($json, true);
foreach ($data[results] as $k => $aArticle) {
$titre = $aArticle[0]['Titre']["href"];
}
$titre = $aArticle->Titre->text;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.