2017-09-26 4 views
3

J'ai un nom d'objet obj comme ça:objet lu PHP attributs

stdClass Object 
(
    [@attributes] => stdClass Object 
     (
      [CurrencyCode] => AUD 
      [CurrencyName] => AUST.DOLLAR 
      [Buy] => 17825.4 
      [Transfer] => 17933 
      [Sell] => 18092.95 
     ) 
) 

J'utilise quelques façons:

  • obj[CurrencyCode]

  • obj ->CurrencyCode

mais ne fonctionnent pas et obtenir erreur: Use of undefined constant CurrencyCode Si l'utilisation: obj -> @attributes pour obtenir l'erreur: syntax error, unexpected ''@attributes'' (T_CONSTANT_ENCAPSED_STRING)

Répondre

3

Vous devez envelopper le @attributes dans le {} Vérifiez l'exemple

<?php 
$abc = array('@attributes' => array('CURR' => 1)); 
$abc = json_decode(json_encode($abc)); 
echo '<pre>'; 
print_r($abc->{"@attributes"}->CURR); 
?>