【发布时间】:2018-07-20 01:04:43
【问题描述】:
我有这个 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>
这就是我写的时候得到的:
return $res;
我如何访问令牌?
我试试:
return $res->Token;
还有
return $res->children();
但此代码返回错误...
SO,我如何访问 XML 中的 Token 或如何转换为 JSON 并轻松访问 $res->Token 等 Token ...
【问题讨论】:
-
把你的xml作为文本而不是图片
-
我把它写成文本
-
$xml = simplexml_load_string($res); echo $xml->Token; -
我像这样解决: res = json_encode(simplexml_load_string($res->getBody())); $res = json_decode($res); $token = $res->令牌;
标签: php json xml laravel object