出现“Fatal error: Cannot use object of type stdClass as array”错误。
我不知道我的做法哪里出错了:
foreach ($json->result->items[$key]->attributes->attribute as $attrib => $val)
{
if($json->result->items[$key]->attributes->attribute[$attrib]->name == 'cannot_trade')
{
$notrade=1;
echo 'Item ' . $key . ' is not tradeable' . $br;
}
}
以下是数据:
[attributes] => stdClass Object
(
[attribute] => Array
(
[0] => stdClass Object
(
[name] => custom employee number
[class] => set_employee_number
[value] => 0
)
[1] => stdClass Object
(
[name] => cannot trade
[class] => cannot_trade
[value] => 1
)
)
)
本质上,我正在尝试测试“属性”数组是否具有无法交易的内容。有时,父对象没有“属性”对象。