2012-04-24 6 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); 
,369를 실행하면 당신은 당신의 개체가이

$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 
         ) 

       ) 

     ) 

) 
관련 문제