gpt4 book ai didi

php - 从 Soap Response PHP 获取属性值

转载 作者:行者123 更新时间:2023-12-04 10:25:05 27 4
gpt4 key购买 nike

我得到了预期的 SOAP 响应,然后转换为数组。这是我的代码:

$response = $client->__getLastResponse();
$response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
$xml = new SimpleXMLElement($response);
$body = $xml->xpath('//soapBody')[0];
$array = json_decode( str_replace('@', '', json_encode((array)$body)), TRUE);
print_r($array);

这是输出:
Array ( 
[GetCompanyCodeResponse] => Array (
[GetCompanyCodeResult] => Array (
[Customers] => Array (
[Customer] => Array (
[attributes] => Array (
[CustomerNo] => 103987
[CustomerName] => epds api testers Inc
[ContactId] => 219196
)
)
)
)
)

我如何回显 ContactId?我试过以下:
$att = $array->attributes();
$array->attributes()->{'ContactId'};
print_r($array);

我收到以下错误:
Fatal error: Uncaught Error: Call to a member function attributes() on array 

还试过:
$array->Customer['CustomerId'];

我收到以下错误:
Notice: Trying to get property 'Customer' of non-object

期待获得219196

最佳答案

我找到了上述问题的解决方案。不确定这是否是最优雅的方法,但它会按预期返回结果。如果有更有效的方法来获取 ContactId,我愿意接受建议。

print_r($array['GetCompanyCodeResponse']['GetCompanyCodeResult']
['Customers']['Customer']['attributes']['ContactId']);

关于php - 从 Soap Response PHP 获取属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60658178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com