如何在Laravel中访问XML或转换为JSON [英] How to access XML or transform to JSON in Laravel

查看:650
本文介绍了如何在Laravel中访问XML或转换为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个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;

如何访问令牌?

我尝试:

return $res->Token; 

还有

return $res->children();

但是此代码返回了我的错误...

but this code returns me errors...

SO,如何使用XML访问令牌或如何转换为JSON并轻松访问令牌,例如$ res-> Token ...

SO, How I can access Token in XML or how to transform into JSON and easy access to Token like $res->Token ...

推荐答案

尝试一下:

$json = $res->getBody();
$array = json_decode($json);

dump($array);

这篇关于如何在Laravel中访问XML或转换为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆