0

我正在尝试将运输 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"];

我不能尝试太多,因为服务没有测试框架,我必须手动取消我创建的所有发货。请告诉我该怎么办。

提前感谢所有帮助。

4

3 回答 3

3

它是对象,而不是数组。您应该使用->来访问该属性。

$order    = $response->Shipments->ProcessedShipment->Reference1;
于 2012-05-18T08:33:57.613 回答
1

那不是一个数组,它是一个stdClass对象(一个通用对象)。

你应该使用$response->Shipments->ProcessedShipment->Reference1

于 2012-05-18T08:35:54.790 回答
1

您使用->运算符来访问对象的属性

$response->Shipments->ProcessedShipment->Reference1;
$response->Shipments->ProcessedShipment->ID;
$response->Shipments->ProcessedShipment->ShipmentLabel->LabelURL;
于 2012-05-18T08:35:47.670 回答