Reputation: 1639
I have this XML response:
<AuthorisationResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://webservice.redletterdays.co.uk/">
<RequestSuccessful>true</RequestSuccessful>
<ErrorMessage/>
<Token>3d3d4a94-87fe-414c-ae0a-fd0e0c4c0060</Token>
</AuthorisationResult>
That's what I got when I write:
return $res;
How can I access Token?
I try :
return $res->Token;
and also
return $res->children();
but this code returns me errors...
SO, How I can access Token in XML or how to transform into JSON and easy access to Token like $res->Token ...
Upvotes: 0
Views: 1065
Reputation: 1639
I solve my problem with:
$res = json_encode(simplexml_load_string($res->getBody()));
$res = json_decode($res);
$token = $res->Token;
Upvotes: 1
Reputation: 11646
Try this:
$json = $res->getBody();
$array = json_decode($json);
dump($array);
Upvotes: 1