PHP/JSON - 标准类对象
问题描述
我对数组还是很陌生.我需要一些帮助 - 我有一些 JSON,我已经通过一些 PHP 运行它,基本上解析 JSON 并将其解码如下:
I'm pretty new to arrays still. I need some help - I have some JSON, and I've run it through some PHP that basically parses the JSON and decodes it as follows:
这实际上一直在继续 - 但是 - 我的问题是 stdClass Object
部分.我需要能够在 for 循环中调用它,然后遍历每个部分(home、score、abbr、to 等).我该怎么办?
This actually goes on and on - BUT - my problem is the stdClass Object
part. I need to be able to call this in a for loop and then iterate through each section (home, score, abbr, to, etc). How would I go about this?
推荐答案
你可以使用 get_object_vars()
来获取对象属性的数组,或者调用 json_decode()
用 json_decode($string,true);
得到一个关联数组.
You can use get_object_vars()
to get an array of the object's properties, or call json_decode()
with json_decode($string,true);
to get an associative array.
示例:
输出:
这篇关于PHP/JSON - 标准类对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!