2016-06-14 64 views
0

我想从soap服务访问一个对象。我的目标是获得ID为53的属性中的值。在此之前,我已使用simplexml_load_string来获取您在下面看到的对象。然而,当试图使用 - >或['']键符号访问对象时,会引发错误。我相信钥匙中的@会导致问题。从soap服务访问对象

我得到以下结果:

作为vardump:

object(SimpleXMLElement)[1951] 
    public '@attributes' => 
    array (size=1) 
     'id' => string '53' (length=2) 

为DD的结果:

SimpleXMLElement {#1951 ▼ 
    +"@attributes": array:1 [▼ 
    "id" => "53" 
    ] 
} 

调试部分:

$result =$service->call('DisplayCategories', [$data]); 

      $result = simplexml_load_string((string)$result->DisplayCategoriesResult->any); 
      // dd($result); 
      $result = $result->categories->category; 
      //dd($result); 
      $tempArr = array(); 

      foreach($result as $item) 
      { 
       // var_dump(html_entity_decode($item)); 
       var_dump($item); 
       dd(((object)$item)); 
       // dd(preg_replace(array("@"),'',$item)); 
       // dd(@simplexml_load_string($item)); 
       dd($item->attributes('id')); 
       $simple = $item->attributes('id'); 
       $resulters = ($item->attributes('id')); 
       dd($resulters); 
      } 

      $this->setResult($result); 
     }); 

回答

2

@attributes是一个函数WHI ch返回一个数组,你不直接访问它。简单地将其别名变为一个变量,然后在完成之后使用索引。

$atts = $item->attributes(); 
dd($atts['id']); 

此外,作为一个侧面说明,cast你的对象的倾销他们当它是一个simple xml object,否则你会看到,你可能是不是在找一些时髦的东西,反正string之前。

+0

谢谢!固体,我看到我有同样的想法,但拉错了财产的价值错误的方式$ item-> attributes('id'); – Scripta55