[英]How to access XML or transform to JSON in Laravel
I have this XML response: 我有这个XML回应:
<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 ... 因此,如何访问XML中的令牌或如何转换为JSON并轻松访问令牌,例如$ res-> Token ...
Try this: 尝试这个:
$json = $res->getBody();
$array = json_decode($json);
dump($array);
I solve my problem with: 我用以下方法解决了我的问题:
$res = json_encode(simplexml_load_string($res->getBody()));
$res = json_decode($res);
$token = $res->Token;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.