简体   繁体   English

如何将Soap Env API响应转换为PHP数组或JSON数组

[英]How to Convert Soap Env API Response into PHP array or JSON array

I am facing the problem for converting Soap Env API Response into a PHP array or JSON array. 我面临将Soap Env API响应转换为PHP数组或JSON数组的问题。 Would you guys, please, let me know how we can do it easily? 你们好吗,请让我知道我们如何轻松做到这一点? How to Convert Soap Env API Response into PHP array or JSON array? 如何将Soap Env API响应转换为PHP数组或JSON数组?

I Got the response of API like below: 我得到了如下的API响应:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <ns6:getLocationByCriteriaResponse xmlns:ns6="http://api.atdconnect.com/atd/3_4/locations" xmlns:c="http://api.atdconnect.com/atd/3_4/common" xmlns:f="http://api.atdconnect.com/atd/3_4/fitments" xmlns:o="http://api.atdconnect.com/atd/3_4/orders" xmlns:p="http://api.atdconnect.com/atd/3_4/products">
            <ns6:locations>
                <ns6:location>
                    <ns6:locationNumber>1104464</ns6:locationNumber>
                    <ns6:locationName>CONCORDE AUTOMOBILE 1990 LTEE</ns6:locationName>
                    <ns6:phoneNumber>4507745336</ns6:phoneNumber>
                    <ns6:customerNumber>507281</ns6:customerNumber>
                    <ns6:address>
                        <c:address1>3003 RUE PICARD</c:address1>
                        <c:city>SAINT-HYACINTHE</c:city>
                        <c:state>QC</c:state>
                        <c:zipCode>J2S1H2</c:zipCode>
                    </ns6:address>
                    <ns6:servicingDC>866</ns6:servicingDC>
                </ns6:location>
                <ns6:location>
                    <ns6:locationNumber>1106909</ns6:locationNumber>
                    <ns6:locationName>CORONADO LUBE</ns6:locationName>
                    <ns6:phoneNumber>9154404222</ns6:phoneNumber>
                    <ns6:customerNumber>507281</ns6:customerNumber>
                    <ns6:address>
                        <c:address1>6508 ESCONDIDO DR</c:address1>
                        <c:city>EL PASO</c:city>
                        <c:state>TX</c:state>
                        <c:zipCode>79912</c:zipCode>
                    </ns6:address>
                    <ns6:servicingDC>615</ns6:servicingDC>
                </ns6:location>
            </ns6:locations>
        </ns6:getLocationByCriteriaResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

This is to convert a string to an array. 这是将字符串转换为数组。

    $string = '1104464CONCORDE AUTOMOBILE 19905......'; // Your Responce

    $array = explode(' ', $string);

    echo '<pre>';

    print_r($array);

Output:
Array
(
    [0] => 1104464CONCORDE
    [1] => AUTOMOBILE
    [2] => 1990
    [3] => LTEE45077453365072813003
    [4] => RUE
    [5] => PICARDSAINT-HYACINTHEQCJ2S1H28661106909CORONADO
    [6] => LUBE91544042225072816508
    [7] => ESCONDIDO
    [8] => DREL
    [9] => PASOTX79912615
)

This is to convert your array to json. 这是将您的数组转换为json。

$string = '1104464CONCORDE AUTOMOBILE 19905......'; // Your Responce
$array = explode(' ', $string); 
$json = json_encode($array); 
echo $json;



 Output: 
    [
    "1104464CONCORDE",
    "AUTOMOBILE",
    "1990",
    "LTEE45077453365072813003",
    "RUE",
    "PICARDSAINT-HYACINTHEQCJ2S1H28661106909CORONADO",
    "LUBE91544042225072816508",
    "ESCONDIDO",
    "DREL",
    "PASOTX79912615"
    ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM