【问题标题】:convert the xml to json array using php使用 php 将 xml 转换为 json 数组
【发布时间】:2018-07-30 11:18:36
【问题描述】:

我正在使用soap api,这是我想要的响应数据。当我使用 php 函数时

<s:Envelope xmlns:s="http">
<s:Body>
    <ValidateESSLoginUsingEmpIDResponse xmlns="http://tempuri.org/">
        <ValidateESSLoginUsingEmpIDResult xmlns:a="" xmlns:i="">
            <a:IsSuccessful>true</a:IsSuccessful>
            <a:Message>Login Successful</a:Message>
        </ValidateESSLoginUsingEmpIDResult>
    </ValidateESSLoginUsingEmpIDResponse>
</s:Body>

它返回数据数组

 $result=str_replace('s:', '', $result);
 $result=str_replace('a:', '', $result);
 $xml=simplexml_load_string($result);
 print_r($xml);

但我不想替换 (S:,a:)。有没有其他方法可以获取该数据

【问题讨论】:

  • 使用DOMDocumentDOMXPathregisterNamespace
  • 我应该在哪里使用它你能解释一下吗
  • 上述 xml 的 sn-p 似乎不完整 - 使用实际代码更容易
  • 是的,我知道我从soap API得到这个响应
  • 使用您的 SOAP 客户端。传输层不用自己动手。

标签: php xml laravel soap php-5.3


【解决方案1】:

我发布了一个将 xml 转换为数组的包。你可以在这里找到它:https://github.com/mtownsend5512/xml-to-array

您可以在您的 xml 上尝试一下,看看会发生什么,但您提供的 xml 似乎无效,因此我建议您尝试使用实际的 soap 响应。

【讨论】:

    猜你喜欢
    • 2012-02-02
    • 1970-01-01
    • 2011-11-03
    • 2018-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 2012-02-08
    相关资源
    最近更新 更多