简体   繁体   English

如何解析PHP中的stdClass对象

[英]How to parse stdClass object in php

Using var_dump from an API call give me the output like this 从API调用中使用var_dump,给我这样的输出

在此处输入图片说明

How to put them into an array? 如何将它们放入数组? thanks 谢谢

You can use json_encode to convert it to a json. 您可以使用json_encode将其转换为json。 After which you can use json_decode with the second parameter set to true which will return an array instead of an StdObject . 之后,您可以将json_decode与第二个参数设置为true ,这将返回一个数组而不是StdObject

If the api you're calling simply returns a json itself then you can go ahead and use json_decode directly with the second argument set to true to yield the same result. 如果您要调用的api本身仅返回一个json,那么您可以继续使用json_decode并将第二个参数设置为true来产生相同的结果。

There are other ways, but this is the simplest. 还有其他方法,但这是最简单的。

You can check out other questions, like this one or this one . 您可以检查其他问题, 例如这个这个

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

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