douzhi1937 2012-05-18 08:32
浏览 52
已采纳

无法在PHP中解析响应对象数组

I am trying to integrate a shipping API with my app. I send my details to a SOAP client and I'm recieiving an object array in return which I am unable to parse. Following is the array. Please help me parse this:

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
            }
        }
    }
}

I took this response in $response variable and tried the following but none of these work:

echo $order    = $response["Shipments"]["ProcessedShipment"]["Reference1"];
echo $hawb     = $response["Shipments"]["ProcessedShipment"]["ID"];
echo $barcode  = $response["Shipments"]["ProcessedShipment"]["ShipmentLabel"]["LabelURL"];

I can't try too much because there is no testing framework with the service I have to manually cancel all the shipments I create. Please tell me what to do.

Thanks in advance for all the help.

  • 写回答

3条回答 默认 最新

  • dongqiaozhe5070 2012-05-18 08:35
    关注

    That's not an array, it's an stdClass object (a general Object).

    You should be using $response->Shipments->ProcessedShipment->Reference1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号