下面是我的代碼,我需要從 beow API 請(qǐng)求中獲取 account_name 的值,請(qǐng)仔細(xì)閱讀并提出建議。我需要獲得的唯一值是account_name值。請(qǐng)幫忙謝謝 $curl = curl_init(); switch ($method){ case "POST": curl_setopt($curl, CURLOPT_POST, 1); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; case "PUT": curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); if ($data) curl_setopt($curl, CURLOPT_POSTFIELDS, $data); break; default: if ($data) $url = sprintf("%s?%s", $url, http_build_query($data)); } // OPTIONS: curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "authorization: Bearer sk_test_df78c3c2d08ea1f266b8b19524a249e77c0eaa14", "content-type: application/json", )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); // EXECUTE: $result = curl_exec($curl); if(!$result){die("Connection Failure");} curl_close($curl); return $result;}$bank="033";$accno=2056194452;$get_data = callAPI('GET', 'https://api.paystack.co/bank/resolve?account_number='.$accno.'&bank_code='.urlencode($bank), false);$response = json_decode(json_encode($get_data), true);echo $response;````#Result of code will output the below:#`{ "status": true, "message": "Account number resolved", "data": { "account_number": "2056194452", "account_name": "OLADEPO WISDOM IBRAHIM", "bank_id": 18 } }`
1 回答

倚天杖
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
API 返回 JSON 數(shù)據(jù),因此沒(méi)有理由對(duì)其進(jìn)行編碼。如果您使用 json_decode 并將“assoc”參數(shù)設(shè)置為 true(就像您已經(jīng)設(shè)置的那樣),它應(yīng)該返回一個(gè)關(guān)聯(lián)數(shù)組。然后您可以從數(shù)組中獲取“account_name”變量。
$get_data = callAPI('GET', 'https://api.paystack.co/bank/resolve?account_number='.$accno.'&bank_code='.urlencode($bank), false);
$response = json_decode($get_data, true);
echo $response['data']['account_name'];
- 1 回答
- 0 關(guān)注
- 134 瀏覽
添加回答
舉報(bào)
0/150
提交
取消