4

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(明らかに)は機能しません。

4

2 に答える 2

10

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

$json->{"/common/topic/article"}[0]->id
于 2012-04-24T21:22:32.870 に答える
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
                        )

                )

        )

)
于 2012-04-24T21:27:36.280 に答える