Php 如何从嵌套数组回显对象?

Php 如何从嵌套数组回显对象?,php,arrays,json,api,Php,Arrays,Json,Api,我使用的是json_解码,我如何回应所有的“所有者”呢 $itemOwners是一个数组。您需要使用以下方法对其进行迭代: 另外,请注意,这不是有效的json。看见似乎在结尾处有一个逗号(在导致语法错误的结尾之前)发布一些代码,该API返回一个包含错误的JSON字符串 <?php $itemOwners = json_decode(file_get_contents("https://www.brick-hill.com//API//serials?id=1937")); echo

我使用的是json_解码,我如何回应所有的“所有者”呢


$itemOwners
是一个数组。您需要使用以下方法对其进行迭代:



另外,请注意,这不是有效的json。看见似乎在结尾处有一个逗号(在导致语法错误的结尾之前)

发布一些代码,该API返回一个包含错误的JSON字符串
<?php

$itemOwners = json_decode(file_get_contents("https://www.brick-hill.com//API//serials?id=1937"));
echo $itemOwners->owner;

?>
<?php

$itemOwners = json_decode(file_get_contents("https://www.brick-hill.com//API//serials?id=1937"));

foreach ( $itemOwners as $owner ) {
    echo $owner->owner;
}

?>