2012-04-24 7 views
4

私はfreebaseデータベースへのAPIリクエストからjson結果を戻しています。 これは$ jsonという名前で返されたオブジェクトの一部です。 $ jsonのvarダンプ:スラッシュでオブジェクトプロパティを取得する

stdClass Object 
(
[name] => Abomey 
[/location/statistical_region/population_growth_rate] => 
[/common/topic/article] => Array 
    (
     [0] => stdClass Object 
      (
       [id] => /m/0jk2c 
      ) 
    ) 

どのようにして/ m/0jk2cの部分を減算できますか?

$ json - >/common/topic/article [0] - > id(明らかに)は動作しません。

答えて

9

これはそれを行う必要があります。

$json->{"/common/topic/article"}[0]->id 
0

これは、あなたが

var_dump($json->{'/location/statistical_region/population_growth_rate'}['/common/topic/article'][0]->id); 
を実行する場合は、あなたのオブジェクトは、この

$std = new stdClass(); 
$std->id = '/m/0jk2c' ; 

$json = new stdClass(); 
$json->name = "Abomey" ; 
$json->{'/location/statistical_region/population_growth_rate'} = array('/common/topic/article'=>array($std)); 

のように見えます

$class->{'/location/statistical_region/population_growth_rate'}['/common/topic/article'][0]->id 

理由を使うべきです

出力

string '/m/0jk2c' (length=8) 

実行

echo "<pre>"; 
print_r($json); 

出力

stdClass Object 
(
    [name] => Abomey 
    [/location/statistical_region/population_growth_rate] => Array 
     (
      [/common/topic/article] => Array 
       (
        [0] => stdClass Object 
         (
          [id] => /m/0jk2c 
         ) 

       ) 

     ) 

) 
関連する問題