我有能够检索1级数组数据的函数,但是在收费后返回JSON字符串中没有级别2。
else if(!empty($_SESSION['SESS_PLAN_BUY_CODE'])){
$pcharge = \Stripe\Customer::create(array(
"source" => $_POST['stripeToken'],
"plan" => $_SESSION['SESS_PLAN_BUY_CODE'],
"email" => $_SESSION["SESS_EMAIL"]
));
echo "My customer id is: " . $pcharge->id;
echo'<br>';
$stuff = json_decode($pcharge->subscriptions);
var_dump($stuff);
实际JSON返回字符串: JSON
上面代码的输出是:
我的客户id
是:cus_6cvCQdpdhmQlGe
NULL
预期产出:
我的客户id
是:cus_6cvCQdpdhmQlGe
1
我试过了:
$stuff = $pcharge->subscriptions[0];
$stuff = $pcharge->subscriptions['total_count'];
$stuff = json_decode($pcharge->subscriptions);
并且很少循环
我得到NULL
或其他一些错误,表明程序员不知道他在做什么。
如何获取Stripe JSON返回字符串中的level 2
和level 3
数据?
答案 0 :(得分:0)
您无需致电json_decode()
,Stripe API会在内部进行所有解码。您只需要访问它返回的对象和数组。
$pcharge = \Stripe\Customer::create(array(
"source" => $_POST['stripeToken'],
"plan" => $_SESSION['SESS_PLAN_BUY_CODE'],
"email" => $_SESSION["SESS_EMAIL"]
));
echo "My customer id is: " . $pcharge->id;
echo'<br>';
$stuff = $pcharge->subscriptions;
echo "Subscription count is: " . count($stuff->data); // total_count isn't returned by default
如果您想访问订阅,请使用$stuff->data[$i]
。