[英]How to convert string as stdClass object to array [PHP]
我正在使用API编写登录系统。 我对使用API的结果感到困惑。 我得到的结果是这样的普通字符串:
stdClass Object
(
[success] => 1
[message] => Array
(
[code] => 000
[txt] => Operation successful
)
[data] => Array
(
[result] => OK
[accountID] => 000000000
[group] => demoCAC
[currency] => USD
[enable] => 1
[read_only] => 0
[name] => Bogus Demo
[country] => ****
[city] =>
[address] =>
[phone] => **
[email] => ***@gmail.com
[status] => test
[regdate] => 07/02/2017 09:57
[lastdate] => 07/02/2017 09:57
[balance] => 0.00
[credit] => 0.00
[equity] => 10000.00
[isDemo] => 1
[tp_version] => **
[last_name] => Demo
[first_name] => Bogus
[domain] => ***.com
[compliance] =>
[latestTrades] => Array
(
[results] => Array
(
)
[totalResults] => 0
)
[owner] =>
)
)
那么如何将其转换为数组或可用变量? *该信息由(echo)打印,并且我无法访问$ result-> data-> ...是否存在将此字符串转换为数组或json或可读性的函数,所以我可以达到特定的值? 当我尝试时:print_r(get_object_vars($ result)); 我收到此错误:
警告:get_object_vars()期望参数1为对象,在第20行的/home/**/public_html/crm/profile.php中给出的字符串
除非我缺少任何东西,否则您的问题很简单。
查看您的var_dump胆量,您应该可以访问问题中的索引,例如:
$result->data['email']; // where 'email' is the key of the data.
要么
$result->data['latestTrades']['results']; // nested example.
标准类的所有属性都是公共的,因此可以直接访问。 在您的示例中,它们全部包含一个数组或嵌套数组,因此可以通过其键进行访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.