我目前正在使用nusoap构建方法调用的webserivce, 我的问题是返回的数组以及如何以可用的方式格式化它,我工作的其他项目返回更简单的结构化xml文件,我可以使用$ xml = simplexml_load_string($ xmlfile);构建和排序我的数组,
这是nusoap电话
$PickUpDateTime='2011-03-17T09:00:00';
$ReturnDateTime='2011-03-21T09:00:00';
require_once('nusoap/lib/nusoap.php');
$wsdl="Srvc.asmx?WSDL";
$client = new nusoap_client($wsdl, 'wsdl');
$param = array('OTA_VehAvailRateRQ' =>
array('VehAvailRQCore' =>
array('VehRentalCore' =>
array('PickUpDateTime'=>$PickUpDateTime,
'ReturnDateTime'=>$ReturnDateTime,
'PickUpLocation' => array('LocationCode' =>$location),
'ReturnLocation' => array('LocationCode' =>$location)
)//PickUpDateTime, ReturnDateTime, PickUpLocation, ReturnLocation
)//VehRentalCore
)//VehAvailRQCore
); //OTA_VehAvailRateRQ
// LOAD OUR VARIABLE WITH THE RETURN ARRAY
$res = $client->call('GetVehAvailRate', $param);
此时我会使用simplexml_load_string();但是这个dosnt似乎可以使用这个调用,执行转储$ res产生..(由于发布限制而丢失了大量数据......但是一旦数组到达Vehicle,那里就会有更多数组。
Array
(
[Success] =>
[VehAvailRSCore] => Array
(
[VehRentalCore] => Array
(
[PickUpLocation] => Array
(
[!LocationCode] => LOCATIONNAME
)
[ReturnLocation] => Array
(
[!LocationCode] => LOCATIONNAME
)
[!PickUpDateTime] => 2011-03-23T09:00:00
[!ReturnDateTime] => 2011-03-31T09:00:00
)
[VehVendorAvails] => Array
(
[VehVendorAvail] => Array
(
[Vendor] => Array
(
[!Code] => AD
)
[VehAvails] => Array
(
[VehAvail] => Array
(
[0] => Array
(
[VehAvailCore] => Array
(
[Vehicle] => Array ()
)
)
[1] => Array
(
[VehAvailCore] => Array
(
[Vehicle] => Array ()
)
)
[2] => Array
(
[VehAvailCore] => Array
(
[Vehicle] => Array()
)
)
[3] => Array
(
[VehAvailCore] => Array
(
[Vehicle] => Array()
)
)
)
[Info] => Array
(
[LocationDetails] =>
)
)
)
)
[!EchoToken] => xxxxxxxx
[!TimeStamp] => 2011-03-18T11:35:19.165125-04:00
[!Target] => xxxxx
[!Version] => xxxxxx
[!TransactionIdentifier] => xxx
)
当尝试使用foreach循环遍历多阵列时,证明比最初想象的要困难得多......
现在当我试图使用foreach循环访问每个元素时,我不得不使用文字调用,即:$ res ['VehAvailRSCore'];还有那些感叹号之前我没有遇到过:ie!LocationCode,normaly这只是$ res-> LocationCode
所以我的问题是这个......我如何利用这个阵列对我有利? 只是这样我可以调用每个数组元素,并可能将这些/这些值添加到另一个数组中,这样我可以更好地格式化我的页面?
感谢
答案 0 :(得分:1)
Dude,nusoap死了。不要使用它。请改用PHP的内置SOAP类。
访问数组值必须使用
$a['key1']['subkey']['subsubkey']['subsubkey']
答案 1 :(得分:1)
只是想发布哪些代码对我有用.. 我已经更改了对nusoap类的调用,并将其替换为PHP SoapClass
$wsdl="..Srvc.asmx?WSDL";
$client = new SoapClient($wsdl);
$param = array('OTA_VehAvailRateRQ' =>
array('VehAvailRQCore' =>
array('VehRentalCore' =>
array('PickUpDateTime'=>$PickUpDateTime,
'ReturnDateTime'=>$ReturnDateTime,
'PickUpLocation' => array('LocationCode' =>$location),
'ReturnLocation' => array('LocationCode' =>$location)
)
)//VehRentalCore
)//VehAvailRQCore
); //OTA_VehAvailRateRQ
$res = $client->__soapCall('GetVehAvailRate', $param);
现在返回的是一个Object,它不会显示那些可怕的感叹号, 为了访问每个值,我使用非文字方式,
foreach($res->subkey->subsubkey->subsubsubkey->subsubsubsubkey as $result) {
echo "<div style='padding:10px; border:1px solid #ccc;'>";
foreach($result as $value){
$string = $value->subkey->subsubkey->subsubsubkey;
echo "<pre>";
print_r($value);
echo "</pre>";
}
echo "</div>";
}
希望其他人可以使用它.. 谢谢你的帮助:)