我有一个来自远程 url 的 json
[{"Name":"Abcd","Alias":["Bcde","Cdef","Fghi","Jklm","Load more"]}]
当我尝试按如下方式打印元素别名时,我收到诸如“尝试获取非对象的属性...”之类的错误
<?php
$json='[{"Name":"Abcd","Alias":["Bcde","Cdef","Fghi","Jklm","Load More"]}]';
$obj=json_decode($json);
foreach($obj->Alias as $val) // Error: Trying to get property of non-object<br/>
echo $val.'<br/>';
?>
解码后的json数组如下
Array
(
[0] => stdClass Object
(
[Name] => Abcd
[Alias] => Array
(
[0] => Bcde
[1] => Cdef
[2] => Fghi
[3] => Jklm
[4] => Load More
)
)
)
我还想从结果中排除最后一个“别名”元素(加载更多)
请...帮助提前谢谢