dongxia527680 2011-04-07 21:31
浏览 41

如何使用php变量/数组(nusoap)检索值

Scenario: I'm using a nusoap.php and connect to a microsoft web service. It returns a result in an array. And it works.

Problem: How to retrieve the value of the DeviceId that is return from the nusoap which is an array? (Because I need to loop this array row by row and get the value of the DeviceId.).

Here's my code: (I print the whole value of an array and the xml)

<?php

require_once('nusoap.php');

$client = new nusoap_client('http://xxx.xxx.xx.xxx:8060/iapps/Service1.asmx?WSDL', true);

$param = array('sql' =>'exec DeviceGet 1 ','p2' => '');
$result = $client->call('GetData',$param , 'Service');

echo print_r($result,true);

echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
?>  

Here's the result:

Array ( [GetDataResult] => Array ( [schema] => Array ( [element] => Array ( [complexType] => Array ( [choice] => Array ( [element] => Array ( [complexType] => Array ( [sequence] => Array ( [element] => Array ( [!name] => DeviceId [!minOccurs] => 0 ) ) ) [!name] => Table1 ) [!minOccurs] => 0 [!maxOccurs] => unbounded ) ) [!name] => NewDataSet [!msdata:IsDataSet] => true [!msdata:UseCurrentLocale] => true ) [!id] => NewDataSet ) [diffgram] => Array ( [NewDataSet] => Array ( [Table1] => Array ( [0] => Array ( [DeviceId] => 00000000-0000-1000-8000-000C29BB0EEA [!diffgr:id] => Table11 [!msdata:rowOrder] => 0 ) [1] => Array ( [DeviceId] => 2f73ba3b80df3636c14e1bafa3818f06d42ebe4d [!diffgr:id] => Table12 [!msdata:rowOrder] => 1 ) [2] => Array ( [DeviceId] => 448252633b4dde13c4cf0431d4055d69ffc70723 [!diffgr:id] => Table13 [!msdata:rowOrder] => 2 ) [3] => Array ( [DeviceId] => 731a2f59b54d38df202315cd3853e3272757febd [!diffgr:id] => Table14 [!msdata:rowOrder] => 3 ) [4] => Array ( [DeviceId] => f855ded29053b276cd99452a454477e5a2d27787 [!diffgr:id] => Table15 [!msdata:rowOrder] => 4 ) ) ) ) ) )

Response
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Thu, 07 Apr 2011 21:18:12 GMT
Connection: close
Content-Length: 1598

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetDataResponse xmlns="http://tempuri.org/"><GetDataResult><xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"><xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="Table1"><xs:complexType><xs:sequence><xs:element name="DeviceId" type="xs:string" minOccurs="0" /></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><NewDataSet xmlns=""><Table1 diffgr:id="Table11" msdata:rowOrder="0"><DeviceId>00000000-0000-1000-8000-000C29BB0EEA</DeviceId></Table1><Table1 diffgr:id="Table12" msdata:rowOrder="1"><DeviceId>2f73ba3b80df3636c14e1bafa3818f06d42ebe4d</DeviceId></Table1><Table1 diffgr:id="Table13" msdata:rowOrder="2"><DeviceId>448252633b4dde13c4cf0431d4055d69ffc70723</DeviceId></Table1><Table1 diffgr:id="Table14" msdata:rowOrder="3"><DeviceId>731a2f59b54d38df202315cd3853e3272757febd</DeviceId></Table1><Table1 diffgr:id="Table15" msdata:rowOrder="4"><DeviceId>f855ded29053b276cd99452a454477e5a2d27787</DeviceId></Table1></NewDataSet></diffgr:diffgram></GetDataResult></GetDataResponse></soap:Body></soap:Envelope>
  • 写回答

1条回答 默认 最新

  • dongxiao9583 2011-04-08 00:32
    关注
    foreach ($result['GetDataResult']['diffgram']['NewDataSet']['Table1'] as $item) {
        echo $item['DeviceId'] . PHP_EOL;
    }
    

    Output:

    00000000-0000-1000-8000-000C29BB0EEA
    2f73ba3b80df3636c14e1bafa3818f06d42ebe4d
    448252633b4dde13c4cf0431d4055d69ffc70723
    731a2f59b54d38df202315cd3853e3272757febd
    f855ded29053b276cd99452a454477e5a2d27787
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题