douwaz34842 2017-04-05 19:02
浏览 66
已采纳

Codeigniter PHP - 解析SOAP(WSDL)结果

I am currently retrieving information from a Web Service using:

$serviceData= new SoapClient('http://xxx.xxx.xxx.xx:xx/WebService/WebService.svc?wsdl');
$response = $serviceData->GetMyInformation();
var_dump($response);

The result from var_dump is below:

object(stdClass)#15 (1) 
{ ["GetDatabaseResult"]=> object(stdClass)#16 (1)
    { ["DatabaseInformation"]=> array(4) 

        {   [0]=> object(stdClass)#17 (2) 
            { ["DateCreated"]=> string(19) "2016-07-06T09:36:03" ["CurrencyCode"]=> string(3) "USD" } 

            [1]=> object(stdClass)#18 (2) 
            { ["DateCreated"]=> string(19) "2016-12-07T02:49:02" ["CurrencyCode"]=> string(3) "USD" } 

            [2]=> object(stdClass)#19 (2) 
            { ["DateCreated"]=> string(19) "2016-12-07T02:52:38" ["CurrencyCode"]=> string(3) "USD" } 

            [3]=> object(stdClass)#20 (2) 
            { ["DateCreated"]=> string(19) "2016-12-07T02:53:38" ["CurrencyCode"]=> string(3) "USD" }

        }
    }
}

What I need is a foreach loop that I can retrieve each key and value:

DateCreated: 2016-07-06T09:36:03
CurrencyCode: USD

I tried using json_encode($response) which removed the object(stdClass)#15 (1) and the json_dencode($response) which got it to this point:

array(1) 
{ ["GetDatabaseResult"]=> array(1) 
    { ["DatabaseInformation"]=> array(4) 
        {   [0]=> array(2) 
            { ["DateCreated"]=> string(19) "2016-07-06T09:36:03" ["CurrencyCode"]=> string(3) "USD" }

            [1]=> array(17) 
            { ["DateCreated"]=> string(19) "2016-12-07T02:49:02" ["CurrencyCode"]=> string(3) "USD" } 

            [2]=> array(17) 
            { ["DateCreated"]=> string(19) "2016-12-07T02:52:38" ["CurrencyCode"]=> string(3) "USD" }

            [3]=> array(17) 
            { ["DateCreated"]=> string(19) "2016-12-07T02:52:38" ["CurrencyCode"]=> string(3) "USD" }

        }
    }
}

I know it's a nested array, but how would I parse it?

  • 写回答

1条回答 默认 最新

  • dongtaigan1594 2017-04-05 19:17
    关注

    No need for the encode/decode loop. Try this:

    foreach($response->GetDatabaseResult->DatabaseInformation as $entry){
      error_log("Date Created: ".$entry->DateCreated."; Currency Code: ".$entry->CurrencyCode);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图