PHP - SOAP response to JSON -
I am trying to parse JSON with SOAP response. So far I have this code:
$ data = '& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; '; $ Data = '& Lt; Soap 12: Envelope xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: soap12 = "http : //www.w3.org/2003/05/soap-envelope "& gt; '; $ Data = '& Lt; Soap 12: Body & gt; '; $ Data = '& Lt; GetCommunities xmlns = "url" & gt; '; $ Data = '& Lt; APIUsername & gt; String & lt; / APIUsername & gt; '; $ Data = '& Lt; APIPSword & gt; String & lt; / APIPassword & gt; '; $ Data = '& Lt; / GetCommunities> '; $ Data = '& Lt; / Soap12: Body & gt; '; $ Data = '& Lt; / Soap12: envelope & gt; '; $ Soap_do = curl_init (); Curl_setopt ($ soap_do, CURLOPT_URL, "url"); Curl_setopt ($ soap_do, CURLOPT_CONNECTTIMEOUT, 10); Curl_setopt ($ soap_do, CURLOPT_TIMEOUT, 10); Curl_setopt ($ soap_do, CURLOPT_RETURNTRANSFER, true); Curl_setopt ($ soap_do, CURLOPT_SSL_VERIFYPEER, incorrect); Curl_setopt ($ soap_do, CURLOPT_SSL_VERIFYHOST, incorrect); Curl_setopt ($ soap_do, CURLOPT_POST, true); Curl_setopt ($ soap_do, CURLOPT_POSTFIELDS, $ data); Curl_setopt ($ soap_do, CURLOPT_HTTPHEADER, array ('content-type: text / xml; charset = UTF-8', 'content-length:' .restion ($ data)); $ Result = curl_xax ($ soap_do); $ Return result; This code is working and I am getting the following result:
I need to create a JSON response from the data that can be found between the GetCommunitiesResult tag. How can I do this?
edit and
// a is a hack, But see ... list ($ garbage, $ result) = explosion ('soap: body & gt;', $ result); List ($ result, $ garbage) = explosion ('& lt; / soap: body & gt;', $ result); Not set ($ trash); $ Result = str_replace ('xmlns = "url"', '', $ result); $ Simple_result = simplexml_load_string ($ result); $ Json_result = json_encode ($ simple_result); // var_export ($ simple_result); Echo $ json_result; ("Community ID": "1", "Community Name": "Community id": "community id": "community id": "community id": "community name": "bella toskana"}, {"community id": "31", "community name": "community id"}, {"community id" "Community id": "community id": "750", "community name": "sunny beach"}, {"community id": "124", "community name": "terra verde resort"} , "Community id": "744", "community name": "dens in west haven"}, {"community id": "158", "community name": "and Strij "}]}}
Comments
Post a Comment