我很多天都坚持这个......我使用这段代码来解析存储在服务器上的json EPG指南:
<?php
$channel = '899';
$current_unix = time();
$json = json_decode(file_get_contents('http://guidatv.sky.it/app/guidatv/contenuti/data/grid/'.date('y_m_d').'/ch_'.$channel.'.js', true));
echo '<ul>';
foreach ($json->plan as $prog) {
echo "<li>" . $prog->title . "</li>";
echo '</ul>';
}
?>
我想跳过这部分json,因为它有空字段
"banned":true,
"plan":[
{"id":"-1",
"pid":"0",
"starttime":"00:00",
"dur":"65",
"title":"",
"normalizedtitle": "",
"desc":"",
"genre":"",
"subgenre":"",
"prima":false
},
我该怎么做?
答案 0 :(得分:1)
您可以在foreach中添加以下条件:
foreach ($json->plan as $prog) {
if(empty($json->plan->title)) continue;
echo "<li>" . $prog->title . "</li>";
}
echo '</ul>';