我从api请求返回到freebase数据库的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(显然)不起作用。
答案 0 :(得分:10)
这应该这样做:
$json->{"/common/topic/article"}[0]->id
答案 1 :(得分:0)
这是你应该使用的
$class->{'/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));
如果你跑
var_dump($json->{'/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
)
)
)
)