我有一个肥皂文件,我试图转换为JSON。我已经意识到,我可以使用simplexml_load_string
没有命名空间,如下如何将SOAP转换为JSON?
$xml = simplexml_load_string($soap_string);
$json = json_encode($xml);
header('Content-Type: application/json');
echo $json;
我的回答下面的XML命名空间有,因此当我尝试使用simplexml_load_string
抛出错误。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<res:ResultMsg xmlns:res="http://api-v1.gen.mm.vodafone.com/mminterface/result">
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>
<Result xmlns="http://api-v1.gen.mm.vodafone.com/mminterface/result">
<ResultType>0</ResultType>
<ResultCode>0</ResultCode>
<ResultDesc>The service request has been accepted successfully.</ResultDesc>
<OriginatorConversationID>555010_jYJlV0MP3y</OriginatorConversationID>
<ConversationID>20170705_00007d59ab9111033601</ConversationID>
<TransactionID>LG51195MWH</TransactionID>
<ResultParameters>
<ResultParameter>
<Key>TransactionAmount</Key>
<Value>100</Value>
</ResultParameter>
<ResultParameter>
<Key>TransactionReceipt</Key>
<Value>LG51195MWH</Value>
</ResultParameter>
<ResultParameter>
<Key>B2CRecipientIsRegisteredCustomer</Key>
<Value>Y</Value>
</ResultParameter>
<ResultParameter>
<Key>B2CChargesPaidAccountAvailableFunds</Key>
<Value>-55.00</Value>
</ResultParameter>
<ResultParameter>
<Key>ReceiverPartyPublicName</Key>
<Value>254713171292 - test test</Value>
</ResultParameter>
<ResultParameter>
<Key>TransactionCompletedDateTime</Key>
<Value>05.07.2017 08:27:38</Value>
</ResultParameter>
<ResultParameter>
<Key>B2CUtilityAccountAvailableFunds</Key>
<Value>32526.00</Value>
</ResultParameter>
<ResultParameter>
<Key>B2CWorkingAccountAvailableFunds</Key>
<Value>541703.00</Value>
</ResultParameter>
</ResultParameters>
<ReferenceData>
<ReferenceItem>
<Key>QueueTimeoutURL</Key>
<Value>https://localhost:443/pay/timeout.php</Value>
</ReferenceItem>
</ReferenceData>
</Result>
]]>
</res:ResultMsg>
</soapenv:Body>
</soapenv:Envelope>
如何取出信封部分从上面,这样我可以保持只有我可以在变轻松地存储和隐蔽它使用simplexml_load_string
到JSON的XML部分SOAP响应?
使用SOAP API(EXT /皂)。 – ThW