I created a database customers.txt where are saved all my created customers in Stripe. Now I want to list all the customers. This is my code in php for listing customers.
我创建了一个数据库customers.txt,其中保存了我在Stripe中创建的所有客户。现在我想列出所有客户。这是我在php中用于列出客户的代码。
$e= \Stripe\Customer::all(array(
'limit' => 3
));
echo $e;
}
But the output is weird:
但输出很奇怪:
Can someone help me to list the customers?
有人可以帮我列出客户吗?
Now I have got my JSON and run this:
现在我有了我的JSON并运行它:
$e=\Stripe\Customer::all(array(
"limit"=>10
));
$customers=json_decode($e,true);
var_dump($customers);
I get just NULL response!
我得到的只是NULL响应!
1 个解决方案
#1
2
That output is not wyrd, it's a Stripe JSON string. standing for Javascript Object Notation (website).
该输出不是wyrd,它是一个Stripe JSON字符串。代表Javascript Object Notation(网站)。
There's a lot of questions on * about JSON so ask things such as How to convert JSON string into a PHP array. Also Stripes own documentation (which is very good), states:
*上有很多关于JSON的问题所以请问诸如如何将JSON字符串转换为PHP数组。 Stripes自己的文档(非常好),声明:
JSON is returned by all API responses, including errors, although our API libraries convert responses to appropriate language-specific objects.
虽然我们的API库将响应转换为适当的语言特定对象,但所有API响应都会返回JSON,包括错误。
来自Stripe文档
Edit: You can read A useful question about turning a JSON string into an object and vice versa
编辑:您可以阅读有关将JSON字符串转换为对象的有用问题,反之亦然
So now you know what JSON is
所以现在你知道JSON是什么了
Using it to get a PHP customer object. (revised)
用它来获取PHP客户对象。 (修订版)
$e // customer JSON of all customers.
$customers = $e->__toArray(true);
//$customers = json_decode($e);
And then process the array $customers
as you need to in your applicaton.
然后在您的应用程序中根据需要处理数组$ customers。
NOTE:
The value of $customers
or $customersArray
will be an Object or a String data type so you need to treat the appropriately, and they will not display with echo
because echo is a string output function, so you need to use print_r()
or var_dump()
to display these values -in their raw form- on the screen.
$ customers或$ customersArray的值将是Object或String数据类型,因此您需要适当地处理它们,并且它们不会显示echo,因为echo是字符串输出函数,因此您需要使用print_r()或var_dump ()以原始形式在屏幕上显示这些值。
EDIT TWO
Recommended that from your screenshot that you format the API response from Stripe into an Array of Objects. This can be done by following this Stack Overflow Answer here.
建议您从屏幕截图中将Stripe的API响应格式化为对象数组。这可以通过此处的Stack Overflow Answer来完成。
Please review my revised code above.
请查看我上面修改的代码。
#1
2
That output is not wyrd, it's a Stripe JSON string. standing for Javascript Object Notation (website).
该输出不是wyrd,它是一个Stripe JSON字符串。代表Javascript Object Notation(网站)。
There's a lot of questions on * about JSON so ask things such as How to convert JSON string into a PHP array. Also Stripes own documentation (which is very good), states:
*上有很多关于JSON的问题所以请问诸如如何将JSON字符串转换为PHP数组。 Stripes自己的文档(非常好),声明:
JSON is returned by all API responses, including errors, although our API libraries convert responses to appropriate language-specific objects.
虽然我们的API库将响应转换为适当的语言特定对象,但所有API响应都会返回JSON,包括错误。
来自Stripe文档
Edit: You can read A useful question about turning a JSON string into an object and vice versa
编辑:您可以阅读有关将JSON字符串转换为对象的有用问题,反之亦然
So now you know what JSON is
所以现在你知道JSON是什么了
Using it to get a PHP customer object. (revised)
用它来获取PHP客户对象。 (修订版)
$e // customer JSON of all customers.
$customers = $e->__toArray(true);
//$customers = json_decode($e);
And then process the array $customers
as you need to in your applicaton.
然后在您的应用程序中根据需要处理数组$ customers。
NOTE:
The value of $customers
or $customersArray
will be an Object or a String data type so you need to treat the appropriately, and they will not display with echo
because echo is a string output function, so you need to use print_r()
or var_dump()
to display these values -in their raw form- on the screen.
$ customers或$ customersArray的值将是Object或String数据类型,因此您需要适当地处理它们,并且它们不会显示echo,因为echo是字符串输出函数,因此您需要使用print_r()或var_dump ()以原始形式在屏幕上显示这些值。
EDIT TWO
Recommended that from your screenshot that you format the API response from Stripe into an Array of Objects. This can be done by following this Stack Overflow Answer here.
建议您从屏幕截图中将Stripe的API响应格式化为对象数组。这可以通过此处的Stack Overflow Answer来完成。
Please review my revised code above.
请查看我上面修改的代码。