您好我想在此对象中获取名称,如何为每个stdClass获取这些名称。
stdClass Object
(
[page] => 0
[items] => 10
[programItems] => stdClass Object
(
[programItem] => Array
(
[0] => stdClass Object
(
[@id] => 8955
[name] => name
)
[1] => stdClass Object
(
[@id] => 8955
[name] => name1
我用
获取此数据$data = json_decode(file_get_contents("http:/example.com"));
答案 0 :(得分:1)
考虑$arr
有std对象数据,
$arr->page;
$arr->items;
foreach($arr->programItems as $a){
foreach($a as $b) {
echo $b->name;
...
}
}
答案 1 :(得分:1)
这应该可以解决问题:
$programItem = $data->programItems;
foreach($programItem as $item){
echo $item->name;
}
答案 2 :(得分:0)
在这里,您将获得$ stdobj中的json数据
$stdobj=json_decode(file_get_contents("http:/example.com"));
echo "Page = ".$stdobj->page."<br>";
echo "item = ".$stdobj->item."<br>";
foreach ($stdobj->programItems as $datas) {
foreach ($datas as $data) {
foreach ($data as $key => $value) {
echo 'key = ' . $key . ', value :' . $value . '<br/>';
}
}
}