PHP 读取对象属性
PHP read object attributes
我有一个像这样的对象名称 obj
:
stdClass Object
(
[@attributes] => stdClass Object
(
[CurrencyCode] => AUD
[CurrencyName] => AUST.DOLLAR
[Buy] => 17825.4
[Transfer] => 17933
[Sell] => 18092.95
)
)
我使用了一些方法:
obj[CurrencyCode]
obj ->CurrencyCode
但不工作并出现错误:Use of undefined constant CurrencyCode
如果使用:
obj -> @attributes
得到错误:syntax error, unexpected ''@attributes'' (T_CONSTANT_ENCAPSED_STRING)
您需要将 @attributes
包裹在 {}
中
检查示例
<?php
$abc = array('@attributes' => array('CURR' => 1));
$abc = json_decode(json_encode($abc));
echo '<pre>';
print_r($abc->{"@attributes"}->CURR);
?>
我有一个像这样的对象名称 obj
:
stdClass Object
(
[@attributes] => stdClass Object
(
[CurrencyCode] => AUD
[CurrencyName] => AUST.DOLLAR
[Buy] => 17825.4
[Transfer] => 17933
[Sell] => 18092.95
)
)
我使用了一些方法:
obj[CurrencyCode]
obj ->CurrencyCode
但不工作并出现错误:Use of undefined constant CurrencyCode
如果使用:
obj -> @attributes
得到错误:syntax error, unexpected ''@attributes'' (T_CONSTANT_ENCAPSED_STRING)
您需要将 @attributes
包裹在 {}
中
检查示例
<?php
$abc = array('@attributes' => array('CURR' => 1));
$abc = json_decode(json_encode($abc));
echo '<pre>';
print_r($abc->{"@attributes"}->CURR);
?>