2017-02-09 32 views
0

變量我使用的是充電API。 API以Json格式接收響應。我需要從PHP中的Json響應中的變量中存儲輸出值。獲取引起從JSON輸出

// Response received from API url 
$output = '{"data":[{"user":"abcd123","bal":"500","error_code":200,"resText":"Success"}]}'; 

//Decoding output 
$json = json_decode($output, true); 

//Print 
print_r($json); 

//Store a value as variable 
$bal = $json['bal']; 

獲取錯誤BAL是不確定的指數。

請幫我用正確的方式來獲得從API響應變量$ BALBAL值。

+1

'print_r($ json);'並遵循結構。 – AbraCadaver

回答

2

你的JSON對象實際存儲的所有數據在稱爲data一個屬性,其又對象數組(只是1真的)。因此,請嘗試

$json['data'][0]['bal'] 
+0

非常感謝!有效。 –