[英]Unable To Parse A Response Object Array In PHP
我正在嘗試將運輸API與我的應用程序集成。 我將詳細信息發送到SOAP客戶端,並且正在接收無法解析的對象數組。 以下是數組。 請幫我解析一下:
object(stdClass)#29 (4) {
["Transaction"]=>
object(stdClass)#30 (5) {
["Reference1"]=>
string(0) ""
["Reference2"]=>
string(0) ""
["Reference3"]=>
string(0) ""
["Reference4"]=>
string(0) ""
["Reference5"]=>
string(0) ""
}
["Notifications"]=>
object(stdClass)#31 (0) {
}
["HasErrors"]=>
bool(false)
["Shipments"]=>
object(stdClass)#32 (1) {
["ProcessedShipment"]=>
object(stdClass)#33 (8) {
["ID"]=>
string(10) "42939401"
["Reference1"]=>
string(9) "100000002"
["Reference2"]=>
string(0) ""
["Reference3"]=>
string(0) ""
["ForeignHAWB"]=>
string(0) ""
["HasErrors"]=>
bool(false)
["Notifications"]=>
object(stdClass)#34 (0) {
}
["ShipmentLabel"]=>
object(stdClass)#35 (2) {
["LabelURL"]=>
string(76) "http://content/rpt_cache/9c0d152bbcdc4e739132d2dsda5506.pdf"
["LabelFileContents"]=>
NULL
}
}
}
}
我將這個響應放入$response
變量中,並嘗試了以下操作,但這些工作均無效:
echo $order = $response["Shipments"]["ProcessedShipment"]["Reference1"];
echo $hawb = $response["Shipments"]["ProcessedShipment"]["ID"];
echo $barcode = $response["Shipments"]["ProcessedShipment"]["ShipmentLabel"]["LabelURL"];
我不能嘗試太多,因為該服務沒有測試框架,我必須手動取消所有創建的貨件。 請告訴我應該怎么做。
在此先感謝您提供的所有幫助。
它是對象,而不是數組。 您應該使用->
訪問該屬性。
$order = $response->Shipments->ProcessedShipment->Reference1;
您使用->
運算符訪問對象的屬性
$response->Shipments->ProcessedShipment->Reference1;
$response->Shipments->ProcessedShipment->ID;
$response->Shipments->ProcessedShipment->ShipmentLabel->LabelURL;
那不是一個數組,而是一個stdClass
對象(一個普通的Object)。
您應該使用$response->Shipments->ProcessedShipment->Reference1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.