0

I have xml response like this enter image description here I want to change to response json like this

{
    "data": {
        "tanggal": "20191015",
        "jam": "103346",
        "BeneficiaryAccount": "12340097034787"
    }
}
brinardi
  • 47
  • 4

1 Answers1

-1

To convert XML data to JSON:

$xml_data = @simplexml_load_string($xml_string);
$json_data = json_encode($xml_data);
$array = json_decode($json_data, TRUE);

This would work.

Prathamesh Doke
  • 797
  • 2
  • 16
  • 38
  • What's `$xml`? Did you mean `$xml_data`? If you meant `$xml_data`, how does this transform to the OP's desired output? – Gordon Oct 15 '19 at 12:46
  • i have try this solution but i get the eror simplexml_load_string(): namespace warning : xmlns: URI iBSMWebService_Rem is not absolute – brinardi Oct 15 '19 at 12:51
  • @brinardi I have updated the answer again, by solving the error that you are facing, try this – Prathamesh Doke Oct 15 '19 at 13:14
  • @PrathameshDoke it still doesnt show how convert the soap response to the json format the OP is asking for. – Gordon Oct 16 '19 at 12:41