简体   繁体   English

尝试使用php列出Stripe中的所有客户时出现奇怪的输出

[英]Weird output when trying to list all customers in Stripe using php

I created a database customers.txt where are saved all my created customers in Stripe. 我创建了一个customers.txt数据库,将所有创建的客户保存在Stripe中。 Now I want to list all the customers. 现在,我要列出所有客户。 This is my code in php for listing customers. 这是我在php中列出客户的代码。

  $e= \\Stripe\\Customer::all(array( 'limit' => 3 )); echo $e; } 

But the output is weird: 但是输出很奇怪:

IMAGE: 图片: 在此处输入图片说明

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响应!

That output is not wyrd, it's a Stripe JSON string. 该输出不是wyrd,而是Stripe JSON字符串。 standing for J ava s cript O bject N otation ( website ). 静置的J ava 小号 CRIPTöbjectÑ浮选( 网站 )。

There's a lot of questions on Stackoverflow about JSON so ask things such as How to convert JSON string into a PHP array . 关于JSON,Stackoverflow上存在很多问题,因此请问如何将JSON字符串转换为PHP数组之类的问题 Also Stripes own documentation (which is very good), states: 还剥离了自己的文档(非常好),其中指出:

JSON is returned by all API responses, including errors, although our API libraries convert responses to appropriate language-specific objects. 尽管我们的API库将响应转换为适当的特定于语言的对象,但所有API响应(包括错误)都会返回JSON。

from the Stripe Documentation 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. 使用它来获取PHP客户对象。 (revised) (修订)

$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. 建议您从屏幕快照中,将Stripe的API响应格式化为对象数组。 This can be done by following this Stack Overflow Answer here . 这可以通过遵循此处的堆栈溢出答案来完成

Please review my revised code above. 请查看我上面的修订代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM