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 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名