Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 访问对象属性?谷歌API_Php_Google Api - Fatal编程技术网

Php 访问对象属性?谷歌API

Php 访问对象属性?谷歌API,php,google-api,Php,Google Api,我想访问对象的属性,但这不起作用: stdClass Object ( [responseData] => stdClass Object ( [results] => Array ( [0] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.speedtest.net/ [url] => http://www.speedtest.net/

我想访问对象的属性,但这不起作用:

stdClass Object ( [responseData] => stdClass Object ( [results] => Array ( [0] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => http://www.speedtest.net/ [url] => http://www.speedtest.net/ [visibleUrl] => www.speedtest.net [cacheUrl] => http://www.google.com/search?q=cache:M47_v0xF3m8J:www.speedtest.net [title] => Speedtest.net by Ookla - The Global Broadband Speed Test [titleNoFormatting] => Speedtest.net by Ookla - The Global Broadband Speed Test [content] => Test your Internet connection bandwidth to locations around the world with this interactive broadband speed test from Ookla. ) [1] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => https://www.test.com/ [url] => https://www.test.com/ [visibleUrl] => www.test.com [cacheUrl] => http://www.google.com/search?q=cache:S92tylTr1V8J:www.test.com [title] => Platform to Create Organizational Testing and Certifications [titleNoFormatting] => Platform to Create Organizational Testing and Certifications [content] => Test.com is a software solution for you to easily create, administer and manage training courses and certification tests, in up to 22 languages. ) [2] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => https://en.wikipedia.org/wiki/Test [url] => https://en.wikipedia.org/wiki/Test [visibleUrl] => en.wikipedia.org [cacheUrl] => http://www.google.com/search?q=cache:R94CAo00wOYJ:en.wikipedia.org [title] => Test - Wikipedia, the free encyclopedia [titleNoFormatting] => Test - Wikipedia, the free encyclopedia [content] => Test, TEST or Tester may refer to: Test (assessment), an assessment intended to measure the respondents' knowledge or other abilities ... ) [3] => stdClass Object ( [GsearchResultClass] => GwebSearch [unescapedUrl] => https://www.speakeasy.net/speedtest/ [url] => https://www.speakeasy.net/speedtest/ [visibleUrl] => www.speakeasy.net [cacheUrl] => http://www.google.com/search?q=cache:sCEGhiP0qxEJ:www.speakeasy.net [title] => Speakeasy Speed Test - Powered by MegaPath [titleNoFormatting] => Speakeasy Speed Test - Powered by MegaPath [content] => Speakeasy, a MegaPath Brand, offers industry leading business voice, data and IT solutions. We ensure the speed, performance and reliability of all our ... ) ) [cursor] => stdClass Object ( [resultCount] => 258,000,000 [pages] => Array ( [0] => stdClass Object ( [start] => 0 [label] => 1 ) [1] => stdClass Object ( [start] => 4 [label] => 2 ) [2] => stdClass Object ( [start] => 8 [label] => 3 ) [3] => stdClass Object ( [start] => 12 [label] => 4 ) [4] => stdClass Object ( [start] => 16 [label] => 5 ) [5] => stdClass Object ( [start] => 20 [label] => 6 ) [6] => stdClass Object ( [start] => 24 [label] => 7 ) [7] => stdClass Object ( [start] => 28 [label] => 8 ) ) [estimatedResultCount] => 258000000 [currentPageIndex] => 0 [moreResultsUrl] => http://www.google.com/search?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=test [searchResultTime] => 0.32 ) ) [responseDetails] => [responseStatus] => 200 )
顺便说一下,它不会抛出错误或警告。它什么也没显示。有什么想法吗


我在谷歌上搜索了它,但找不到关于谷歌搜索API以及如何使用搜索查询结果的更多信息。

您可以通过$json->responseData->results[$x]访问所需元素。其中$x是元素编号

或者,您也可以简单地将整个过程循环为

$jsonNew = $json->{'results'};
print_r($jsonNew);
用于($x=0;$xresponseData->results)$x++){
echo“
URL:”; echo$json->responseData->results[$x]->url; 回声“
可见URL:”; echo$json->responseData->results[$x]->visibleUrl; 回声“
标题:”; echo$json->responseData->results[$x]->title; 回声“
内容:”; echo$json->responseData->results[$x]->content; 回声“
”; }
您忘记了
responseData
propertyPerhaps$json->responseData->results[0]?是的。就这样。非常感谢。
$jsonNew = $json->{'results'};
print_r($jsonNew);
for($x=0;$x<count($json->responseData->results);$x++){

  echo "</br>URL: ";
  echo $json->responseData->results[$x]->url;
  echo "</br>VisibleURL: ";
  echo $json->responseData->results[$x]->visibleUrl;
  echo "</br>Title: ";
  echo $json->responseData->results[$x]->title;
  echo "</br>Content: ";
  echo $json->responseData->results[$x]->content;
  echo "</br>";

}