注意:未定义的属性:stdClass :: $ Image php

时间:2015-06-08 14:25:49

标签: php bing

我检查过以前类似的线程,但没有得到任何解决方案。我试图从bing image api

访问图像搜索结果
<form method="post" action="">
    Type in a search:<input type="text" id="searchText" name="searchText"
    value="<?php    
        if (isset($_POST['searchText']))
        {
            echo($_POST['searchText']);
        }
        else { echo('sushi');}
    ?>"/>
    <input type="submit" value="Search!" name="submit" id="searchButton" />
    <?php
    if (isset($_POST['submit'])) {
    $request = 'http://api.bing.net/json.aspx?Appid=t58HB/yo6AEdw7/AMUb4k9kjJv/JRGUNX4&sources=image&query='.urlencode( $_POST["searchText"]);
    $response = file_get_contents($request);
    $jsonobj = json_decode($response);
    echo gettype($jsonobj);
    echo('<ul ID="resultList">');
    foreach($jsonobj->SearchResponse->Image->Results as $value)
    {
    echo('<li class="resultlistitem"><a href="' . $value->Url . '">');
    echo('<img src="' . $value->Thumbnail->Url. '"></li>');
    }
    echo("</ul>");
    } ?>
</form>

跟随这个啧啧 - http://www.bing.com/developers/s/APIBasics.html#_Using_the_API

获取错误:

Notice: Undefined property: stdClass::$Image in /opt/lampp/htdocs/tindex2.php on line 33

Notice: Trying to get property of non-object in /opt/lampp/htdocs/tindex2.php on line 33

Warning: Invalid argument supplied for foreach() in /opt/lampp/htdocs/tindex2.php on line 33

任何建议都非常明显。

0 个答案:

没有答案