尝试从json_decode()
未定义的索引AccontNumber
我已经尝试将Isset用于变量并且没有得到任何结果,我在哪里做错了?
$this->getToken();
$path = '/banking/v2/corporates/BCAAPI2016/accounts/0201245680/statements?StartDate=2016-09-01&EndDate=2016-09-01';
$method = 'GET';
$data = array();
$this->getSignature($path, $method, $data);
$headers = array(
'X-BCA-Key: '.self::$api_key,
'X-BCA-Timestamp: '.self::$timestamp,
'Authorization: Bearer '.self::$access_token,
'X-BCA-Signature: '.self::$signature,
'Content-Type: application/json',
'Origin: '.$_SERVER['SERVER_NAME']
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::$main_url.$path);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => $headers,
));
$output = curl_exec($ch); // This is API Response
curl_close($ch);
//this part I get error
$result = json_decode($output,true);
return view("bca.bca", [
"result" => $result
]);
我的观点
@if ($result['AccountDetailDataSuccess'])
{{ $result['AccountNumber'] }}
{{ $result['Currency'] }}
{{ $result['Balance'] }}
{{ $result['AvailableBalance'] }}
{{ $result['FloatAmount'] }}
{{ $result['HoldAmount'] }}
{{ $result['Plafon'] }}
@elseif ($result['AccountDetailDataFailed'])
{{ $result['English'] }}
{{ $result['Indonesian'] }}
{{ $result['AccountNumber'] }}
@endif
这是我var_dump($result)
array(2) { ["AccountDetailDataSuccess"]=> array(1) { [0]=> array(7) { ["AccountNumber"]=> string(10) "0201245680" ["Currency"]=> string(3) "IDR" ["Balance"]=> string(12) "118849999.53" ["AvailableBalance"]=> string(12) "118849999.53" ["FloatAmount"]=> string(4) "0.00" ["HoldAmount"]=> string(4) "0.00" ["Plafon"]=> string(4) "0.00" } } ["AccountDetailDataFailed"]=> array(0) { } }
如何从JSON结果中调用一个单独的数组?
答案 0 :(得分:2)
AccountNumber位于AccountDetailDataSuccess数组中,因此调用
$result['AccountDetailDataSuccess'][0]['AccountNumber']
同样适用于货币等。