2016-06-14 10 views
0

soapサービスからオブジェクトにアクセスしようとしています。私の目的は、53のIDのプロパティで値を取得することです。このポイントに入る前に、私はsimplexml_load_stringを使用して、以下に示すオブジェクトにアクセスしました。ただし、 - >または["']キー表記を使用してオブジェクトにアクセスしようとすると、エラーがスローされます。私は鍵の@が問題を引き起こしていると信じています。 DD結果としてsoapサービスからオブジェクトにアクセスする

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

:vardumpとして

iは、次のような結果を得る

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は配列を返しますが、直接アクセスすることはありません。単純にそれを変数にエイリアスしてから、それを実行した後にインデックスを操作してください。サイドノート、castあなたのオブジェクトとして、それはsimple xml objectだときにそれらをダンプする前にstringにも

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

、そうでなければ、とにかく、あなたはおそらく探しされていないいくつかのファンキーなものが表示されます。

+0

ありがとう!私は同じアイデアを持っていたが、プロパティの値を間違った方法$ item-> attributes( 'id'); – Scripta55

関連する問題