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 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,