我面临将Soap Env API Response转换为PHP数组或JSON数组的问题。 请你们,让我知道我们如何轻松地做到这一点? 如何将Soap Env API响应转换为PHP数组或JSON数组?
我得到了如下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>
答案 0 :(得分:0)
这是将字符串转换为数组。
$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
)
这是为了将你的数组转换为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"
]