如何将Amadeus Flight Search API返回的Soap xml响应转换为json

时间:2019-12-16 10:08:42

标签: php json xml soap amadeus

我想将SOAP XML响应转换为JSON格式。有人可以帮忙吗!

我在$ response中低于SOAP XML

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:awsse="http://xml.amadeus.com/2010/06/Session_v3" xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soapenv:Header>
    <wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
    <wsa:From>
        <wsa:Address>https://nodeD2.test.webservices.amadeus.com/XXXXXXXX</wsa:Address>
    </wsa:From>
    <wsa:Action>http://webservices.amadeus.com/FMPTBQ_18_1_1A
    </wsa:Action>
    <wsa:MessageID>urn:uuid:a4844bc6-2e05-e8e4-b589-6f813ecad262</wsa:MessageID>
    <wsa:RelatesTo RelationshipType="http://www.w3.org/2005/08/addressing/reply">urn:uuid:ac1c8436-ecaf-4bbb-a9ff-11b466dffe18</wsa:RelatesTo>
    <awsse:Session TransactionStatusCode="End"><awsse:SessionId>00896YTRZQPQ</awsse:SessionId><awsse:SequenceNumber>1</awsse:SequenceNumber><awsse:SecurityToken>TRFTGYNBHUYKIOL</awsse:SecurityToken></awsse:Session>
</soapenv:Header>
<soapenv:Body>
    <Fare_MasterPricerTravelBoardSearchReply xmlns="http://xml.amadeus.com/FMPTBR_18_1_1A">
        <replyStatus><status><advisoryTypeInfo>FQX</advisoryTypeInfo></status></replyStatus>
        <conversionRate><conversionRateDetail><currency>USD</currency></conversionRateDetail></conversionRate>
        <familyInformation><refNumber>1</refNumber><fareFamilyname>BAGSEAT</fareFamilyname><description>OPTIMA</description><carrier>IB</carrier><services><reference>1</reference><status>CHA</status></services><services><reference>2</reference><status>CHA</status></services><services><reference>3</reference><status>INC</status></services><services><reference>4</reference><status>NOF</status></services><services><reference>5</reference><status>NOF</status></services><services><reference>6</reference><status>NOF</status></services><services><reference>7</reference><status>NOF</status></services></familyInformation>
    </Fare_MasterPricerTravelBoardSearchReply>
</soapenv:Body>
</soapenv:Envelope>

我尝试过这个。

$xml = json_decode(json_encode(simplexml_load_string($response)), true);
print '<pre>';
print_r($xml);
print '</pre>';

1 个答案:

答案 0 :(得分:-1)

我找到了解决问题的方法,工作正常

$response  = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
$response  = simplexml_load_string($response);
$dataArray = json_decode(json_encode((array)$response), TRUE);

echo '<pre>';print_r($dataArray);echo '</pre>';die(__FILE__.' On this line '.__LINE__);