我使用PHP
调用AJAX
脚本,其数据类型为JSON
,后者又调用SoapClient Web服务。
然后我使用以下命令将返回的stdClass数组转换为PHP
数组
$array = json_decode(json_encode($response), true);
打印时看起来像这样:
Array
(
[QueryResult] => OK
[status] => 1
[description] => Authorised
[authorisation] => Array
(
[XElement] => Array
(
[0] => Array
(
[any] => 999777
)
[1] => Array
(
[any] => 44**********1111
)
[2] => Array
(
[any] => 34490704
)
[3] => Array
(
[any] => 05/27
)
[4] => Array
(
[any] => 1000
)
[5] => Array
(
[any] => 1000
)
[6] => Array
(
[any] => 0
)
[7] => Array
(
[any] => 444433124490719785137937321111
)
[8] => Array
(
[any] => VC
)
)
)
)
我然后json_encode
将其返回到我的AJAX
电话,但我在这里得到XML
,例如:
<CardNo xmlns="">44**********1111</CardNo>
但我只想要卡号 - 而不是封闭标签 - 可能吗?我一整晚都在努力,我准备拔出最后一根头发!
PHP代码
try {
$soapclient = new SoapClient($wsdl, array('trace' => 1));
$params = array (
'account' => $account,
'user' => $user,
'password' => $password,
'id' => $id,
'status' => $status,
'description' => $description,
'authorisation' => $authorisation
);
$response = $soapclient->Query($params);
$array = json_decode(json_encode($response), true);
$data["status"] = $array["status"];
$data["description"] = $array["description"];
$data["AuthCode"] = $array["authorisation"]["XElement"][0]["any"];
$data["CardNo"] = $array["authorisation"]["XElement"][1]["any"];
$data["MPOSID"] = $array["authorisation"]["XElement"][2]["any"];
$data["CardExpiry"] = $array["authorisation"]["XElement"][3]["any"];
$data["Amount"] = $array["authorisation"]["XElement"][4]["any"];
$data["Paid"] = $array["authorisation"]["XElement"][5]["any"];
$data["Surcharge"] = $array["authorisation"]["XElement"][6]["any"];
$data["Token"] = $array["authorisation"]["XElement"][7]["any"];
$data["CardType"] = $array["authorisation"]["XElement"][8]["any"];
echo json_encode($data);
}