2015-09-01 164 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