PHP - SOAP数组stdClass

时间:2014-10-22 13:27:05

标签: php arrays soap

所以我试图解析我从SOAP查询中得到的一系列结果。然而PHP似乎让我感到悲伤(更可能是我给自己悲伤)。我想要回显从查询中检索的所有用户对象。

查询结果:

object(stdClass)#3 (1) { ["row"]=> array(4) { 
[0]=> object(stdClass)#4 (2) { ["pkid"]=> string(36) "0c69d6a4-a4a7-0a68-ac47-e3b9279fb25e" ["userid"]=> string(7) "Kitchen" } 
[1]=> object(stdClass)#5 (2) { ["pkid"]=> string(36) "60c858b6-71fd-4c6b-0bc7-18c56a07127e" ["userid"]=> string(7) "Control" } 
[2]=> object(stdClass)#6 (2) { ["pkid"]=> string(36) "b59301fc-a197-6d50-b217-7d8967332601" ["userid"]=> string(5) "House" } 
[3]=> object(stdClass)#7 (2) { ["pkid"]=> string(36) "dcf8b18d-cf95-4ffd-85d2-a6f9b45f5fc9" ["userid"]=> string(47) "Token_User_4806a7a1-f23d-4647-b46c-f62ad66452a0" } } }

结果代码:

$response = $client->executeSQLQuery(array("sql"=>"select pkid,userid from enduser"));
    //        var_dump($response);
    foreach ($response as $row){
        var_dump($row);
}

现在我可以通过更改代码来深入了解数组:

    foreach ($response as $row){
        var_dump($row->row);
}

但是,仅仅访问userid元​​素并不起作用:

    foreach ($response as $row){
        var_dump($row->row->userid);
}

PHP返回: PHP Notice: Trying to get property of non-object

非常感谢任何帮助,谢谢。

快速更新: 来源查询:

$response = $client->executeSQLQuery(array("sql"=>"select pkid,userid from enduser"));
    //        var_dump($response);
    foreach ($response as $row){
      var_dump($row);
//echo("USER: ".$row->userid)."<br>";
}
var_dump的{​​p> $row返回:

object(stdClass)#3 (1) { ["row"]=> array(4) { [0]=> object(stdClass)#4 (2) { ["pkid"]=> string(36) "0c69d6a4-a4a7-0a68-ac47-e3b9279fb25e" ["userid"]=> string(7) "Kitchen" } [1]=> object(stdClass)#5 (2) { ["pkid"]=> string(36) "60c858b6-71fd-4c6b-0bc7-18c56a07127e" ["userid"]=> string(7) "Control" } [2]=> object(stdClass)#6 (2) { ["pkid"]=> string(36) "b59301fc-a197-6d50-b217-7d8967332601" ["userid"]=> string(5) "House" } [3]=> object(stdClass)#7 (2) { ["pkid"]=> string(36) "dcf8b18d-cf95-4ffd-85d2-a6f9b45f5fc9" ["userid"]=> string(47) "Token_User_4806a7a1-f23d-4647-b46c-f62ad66452a0" } } }
var_dump的{​​p> $response返回:

object(stdClass)#2 (1) { ["return"]=> object(stdClass)#3 (1) { ["row"]=> array(4) { [0]=> object(stdClass)#4 (2) { ["pkid"]=> string(36) "0c69d6a4-a4a7-0a68-ac47-e3b9279fb25e" ["userid"]=> string(7) "Kitchen" } [1]=> object(stdClass)#5 (2) { ["pkid"]=> string(36) "60c858b6-71fd-4c6b-0bc7-18c56a07127e" ["userid"]=> string(7) "Control" } [2]=> object(stdClass)#6 (2) { ["pkid"]=> string(36) "b59301fc-a197-6d50-b217-7d8967332601" ["userid"]=> string(5) "House" } [3]=> object(stdClass)#7 (2) { ["pkid"]=> string(36) "dcf8b18d-cf95-4ffd-85d2-a6f9b45f5fc9" ["userid"]=> string(47) "Token_User_4806a7a1-f23d-4647-b46c-f62ad66452a0" } } } }

1 个答案:

答案 0 :(得分:1)

我愚蠢,这是我在另一篇文章中遇到的同样问题。我基本上需要访问return->row个对象,然后才能访问数组中的pkiduserid属性。

最终代码如下:

$response = $client->executeSQLQuery(array("sql"=>"select pkid,userid from enduser"));
//        var_dump($response);
foreach ($response->return->row as $row){
//        var_dump($row->userid);
echo("USER: ".$row->userid)."<br>";
}