1

嗨,我无法做到这一点。我想从这个返回的 json 结果
全文中获取 totalResults:http ://code.google.com/apis/customsearch/v1/using_rest.html

  "request": [
   {
    "title": "Google Custom Search - flowers",
    "totalResults": 10300000,
    "searchTerms": "flowers",
   }
  ]
 },

我试过这个:

$response = file_get_contents('https://www.googleapis.com/customsearch/v1?key=INSERT-YOUR-KEY&cx=013036536707430787589:_pqjad5hr1a&q=flowers&alt=json
');
$json = json_decode($response);
echo "Total Result:".$json->request->totalResults;

但我什么也没有。需要帮助。谢谢。

4

2 回答 2

1

在您的帖子中,所有 json 都不可见。在我的测试中,它适用于:

$json->queries->request[0]->totalResults;

于 2011-09-02T08:35:21.687 回答
0

也许尝试 if(!is_null($json->request->totalResults)) 条件来查看您是否甚至收到响应。

于 2011-02-20T21:36:56.637 回答