下面是下面编写的代码的结果,我想在其中获取第一个 id 元素,并将其等于一个 php 变量,例如 $customerID = whats in the green
下面是这个json数据是如何生成的:
try {
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'cad',
'capture' => 'false',
'description'=> $courseTitle
));
$charge_json = $charge->__toJSON();
$charge_json->_values['id'];
echo "<pre>";
var_dump($charge_json);
echo "</pre>";
} catch(\Stripe\Error\Card $e) {
// The card has been declined
$stripChargeValid = false;
echo "failed";
}
注意:
在第 58 行发现的错误通知如下:
$charge_json->_values['id'];
我执行以下行的原因是因为其核心是填充的 json 数据受到保护,因此我无法获取 ID:
$charge_json = $charge->__toJSON();
最佳答案
您需要json_decode()
$customer 数据(您发布的json 图像)。之后您可以通过 $customer->id
访问该 id。在 json_decoded $customer 上调用 print_r()
以查看其结构。
关于php - 使用 PHP 获取 JSON 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29837133/