缺少JSON端点,返回选项

时间:2014-12-07 17:52:35

标签: php json

任何人都可以通过使用JSON端点请求遇到的一个小问题来解决问题。我对PHP不是很了解。当调用端点并且没有找到数据时,我想用本地图像源替换它。在这种情况下,我打电话给brewery-> logo_url。大多数条目都有端点,但有些则没有。当在端点处找到图像链接时,它会抛弃我的布局。你可以看到那些看起来的东西。它们与左侧对齐。我想在每次发生这种情况时用徽标默认图像替换,希望将布局调整恢复正常。

这是我的工作文件 http://graintoglass.com/facebook-tabs/

这是JSON。 http://mcallen.taphunter.com/widgets/locationWidget?location=Grain-To-Glass&format=jsonv2short

代码努力:

<?php $url = 'http://mcallen.taphunter.com/widgets/locationWidget?location=Grain-To-Glass&format=jsonv2short&servingtype=bottlecan';
$curl_session = curl_init($url);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt($curl_session, CURLOPT_TIMEOUT, 10);
$data = curl_exec($curl_session);
curl_close($curl_session);
$beer_list = json_decode($data);
echo '<p class="last-updated">Last Updated: ' . date("m/d/Y") . '</p>';
echo '<h1 class="page-title">Bottle List</h1>';
echo '<p class="page-intro">Not only do we serve a hefty list of brews on tap, we also offer an exclusive list of beers in bottle. Our bottle list is constantly changing so the occasional return visits to browse this list is the best way to stay up to date. Take a look!</p>';
foreach ($beer_list as $beer)
{
    echo '<article class="beer-entry">
    <div class="beer-image"><img src="'.$beer->brewery->logo_url.'" /></div>
    <div class="beer-info">
        <p class="brewery-name">'.$beer->brewery->name.'&nbsp;&mdash;&nbsp;'.$beer->brewery->origin.'</p>
        <h2 class="beer-name">'.$beer->beer->name.'</h2>
        <p class="beer-style">Beer Style: '.$beer->beer->style.'</p>
        <p class="beer-description">'.$beer->descriptions->short_description.'</p>
        <p class="beer-abv">ABV: '.$beer->beer->abv.'&nbsp;&nbsp;&#47;&nbsp;&nbsp;IBU: '.$beer->beer->ibu.'</p>
        <p class="beer-ibu"></p>
    </div>

    <div class="clearfix"></div>
    </article>
    '; 
}
echo '<p class="page-bottom">If you would like to see more of our food and beer options, <a href="https://www.graintoglass.com" target="_blank">visit our website</a>.</p>';

?>

0 个答案:

没有答案