stdClass object的处理

php取回的json数据是stdClass,要将数据处理成数组,需要用get_object_vars函数,但是该函数只能将第一级对象转为数组

例子:
$back_info = file_get_contents(“http://xxxx/act/cps_api/gamelist/index/?game_ids=” . $ids);
$back_temp = json_decode($back_info);
$back = get_object_vars($back_temp);
foreach ($back as $k => $v) {
print_r($k);
echo “<br />”;
print_r($v);
exit;
}
输出:
97<br />stdClass Object
(
    [game_name] => 神仙道
    [server_info] => stdClass Object
        (
            [894] => stdClass Object
                (
                    [server_number] => 双线94区
                    [server_name] => 九鼎记事
                    [game_url] => http://xxxx/webgame/index/sxd/s94?from=0gsp_cps2345&source=cps&from_ly=cps2345
                )
        )
)
如果要访问stdClass的某个子元素:例$v->game_name

发表评论

电子邮件地址不会被公开。 必填项已用*标注