我使用了一个以XML
格式返回结果的 Web 服务。该方法simplexml_load_string()
用于将其转换为如下对象:
$xml = simplexml_load_string($result[$webresult]);
下面是使用的示例显示
print_r($xml)
:
SimpleXMLElement Object ( [record] => SimpleXMLElement Object ( [txnref] => 6113229211825720 [channel] => mastercard [amount] => 3000.00 [payment_date] => 8/17/2013 9:18:25 PM [payment_status] => successful [field_values] => SimpleXMLElement Object ( [field_values] => SimpleXMLElement Object ( [field] => Array ( [0] => SimpleXMLElement Object ( [names] => Frank [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [1] => SimpleXMLElement Object ( [amount] => 3000 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [2] => SimpleXMLElement Object ( [currency] => NGN [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [3] => SimpleXMLElement Object ( [email_address] => chibuzo.henry@gmail.com [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [4] => SimpleXMLElement Object ( [phone_number] => 08035653468 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) [5] => SimpleXMLElement Object ( [merch_txnref] => 134 [acct_desc] => False [acct_desc_order] => 0 [hidden] => False [defaultvalue] => SimpleXMLElement Object ( ) [xpath_field] => 0 ) ) ) ) [payment_status_description] => Transaction Successful - Approved ) )
但是,当我尝试访问 object$xml
时,这样:
$xml->amount;
它不返回任何结果。如何正确访问对象的属性?