![](/img/trans.png)
[英]How convert to array or json php soap __dorequest response?
[英]How to Convert Soap Env API Response into PHP array or JSON array
我面臨將Soap Env API響應轉換為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>
這是將字符串轉換為數組。
$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"
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.