给出未定义属性 stdClass 的目标数组


Objective array giving Undefined property stdClass?

简单地说,我有JSON数组,它转换为目标数组以使用它。
每次我尝试从数组中回显任何属性(对象)时,它都会给出错误

Undefined property: stdClass::$title

这是数组

stdClass Object
(
    [info] => stdClass Object
        (
            [title] => Categories
            [num_of_cate] => 5
            [color] => grey
        )
)

原始 JSON 数组

{"info":{"title":"Categories","num_of_cate":5,"color":"grey"}}

这就是我试图呼应财产的方式

echo $info->title

试试这个:

$json = '{"info":{"title":"Categories","num_of_cate":5,"color":"grey"}}';
$decoded = json_decode($json);
echo $decoded->info->title; // Categories

目前,您正在尝试访问等效的 $decoded->title ,它不存在 - 因此出现错误。