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

时间:2017-07-02 15:24:25

标签: php arrays json api

我正在使用json_decode,如何回应此https://www.brick-hill.com/API/serials?id=20

的所有“所有者”
<?php

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

?>

1 个答案:

答案 0 :(得分:0)

$itemOwners是一个数组。您需要使用foreach迭代它:

<?php

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

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

?>

另外,请注意,这不是有效的json。见here。看起来你最后有一个逗号(在结束]之前导致语法错误)

相关问题