2015-09-01 121 views
0

在PHP中使用Stripe API所有试图从其中取出值的操作都返回null,r根本不显示结果。我试过Stripe API JSON返回null

$customers = \Stripe\Customer::all(); 
$customers_json = $customers->__toJSON(); 
json_decode($customers_json); 

echo $customers_json->data->id; 

$customers = \Stripe\Customer::all(); 
$customer = $customers->__toArray(true); 

echo $customer["data"]["id"]; 

但每次结果都在一个空白的回声。然而,当我只输出原始变量而不解析为JSON或任何东西时,它会返回一个完整的JSON值的字符串,而不是解析。的只是原始$customers输出是

Stripe\Collection JSON: { "object": "list", "has_more": false, "url": "\/v1\/customers", "data": [ { "id": "cus_6u32tOQ6MRXuqm", "object": "customer", "created": 1441114587, "livemode": false, "description": "test customer", "email": "[email protected]", "shipping": null, "delinquent": false, "metadata": [ ], "subscriptions": { "object": "list", "total_count": 0, "has_more": false, "url": "\/v1\/customers\/cus_6u32tOQ6MRXuqm\/subscriptions", "data": [ ] }, "discount": null, "account_balance": 0, "currency": null, "sources": { "object": "list", "total_count": 0, "has_more": false, "url": "\/v1\/customers\/cus_6u32tOQ6MRXuqm\/sources", "data": [ ] }, "default_source": null } ] } 
+0

你能否告诉我们'$客户'全力输出? – arik

+0

现在加入吧,对不起 – Wargog

回答

1

的问题是,所述数据字段是不是一个对象,但对象的数组。与$customer = $customers->__toArray(true);方法坚持,你应该尝试以下操作:

​​

如果您希望通过所有客户进行迭代,尝试这样做:

foreach($customer['data'] as $currentCustomerData){ 
    // do stuff here 
} 
+0

已经工作了,非常感谢 – Wargog