我似乎无法找到这个在线的答案,但我认为这是因为我不太确定要搜索什么,因为我对xml和json很陌生。json decode获取属性
如果我有这样的XML
$postData = '<PaymentNotification Stage="false">
<MerchantReference>100004117</MerchantReference>
<TransactionType>PAYMENT</TransactionType>
<TransactionState>SUCCESSFUL</TransactionState>
<ResultCode>00</ResultCode>
<ResultMessage>Successful</ResultMessage>
<PayUReference>1167986976014</PayUReference>
<Basket>
<Description>Store Order Number:100004117</Description>
<AmountInCents>100</AmountInCents>
<CurrencyCode>ZAR</CurrencyCode>
<Products/>
</Basket>
<PaymentMethodsUsed>
<Eft BankName="ABSA" AmountInCents="100" Reference="CUMVSIUPFG" AccountNumber="4077920871" BranchNumber="632005" AccountType="Cheque" TimeLimit="168" Currency="ZAR"/>
</PaymentMethodsUsed>
<IpnExtraInfo>
<ResponseHash></ResponseHash>
</IpnExtraInfo>
</PaymentNotification>';
然后JSON解码它
$returnData = json_decode(json_encode(simplexml_load_string($postData)),true);
我可以检索的对象如。
$cost_amount = $returnData['Basket']['AmountInCents'];
但是,我如何获得在EFT的属性例如。银行名?
我尝试了这些没有成功
$paid_amount = $returnData['PaymentMethodsUsed']['CreditCard']['@AmountInCents'];
and
$paid_amount = $returnData[0]->PaymentMethodsUsed[0]->CreditCard->AmountInCents;
这就是为什么有时这种方法不会削减它,它不是一个完美的方法来使用,因为它不能完美地保存数据,你只需要走它正常的方式 – Ghost 2014-09-27 14:07:42
它也没有那么糟糕 - 旁边有许多重复它现场 - 首先阅读它在PHP手册:[基本的SimpleXML用法](http://php.net/manual/en/ simplexml.examples-basic.php) – hakre 2014-09-28 08:38:59