2015-04-05 28 views
0

我正在關注Guzzle的文檔,並在json響應中卡住了。這是我的代碼未定義的偏移量:在json響應var_dump()期間Guzzle中的0

require 'vendor/autoload.php'; 
use GuzzleHttp\Client; 

$client = new Client(); 
$response = $client->get('http://httpbin.org/get'); 
$json = $response->json(); 
var_dump($json[0]['origin']); 

當我運行這個文件,我得到的錯誤

Notice: Undefined offset: 0 in C:\xampp\htdocs\guzzle\config.php on line 8 
NULL 

爲什麼會出現不確定的偏移?

+0

當你執行'var_dump($ json)'時返回什麼? – Aiias 2015-04-05 02:23:04

回答

0

以前的堆棧溢出問題可以提供相同的問題和答案,可以找到herehere

Guzzle Docs

狂飲使用json_decode PHP()方法和使用陣列而不是stdClass的對象的對象。

PHP試圖訪問$ json數組的鍵0。它沒有找到一個值,而是遇到[0]的未定義偏移量並拋出錯誤。