1

freebase API を使用しています。curl 操作の結果を取得したら、json を PHP にデコードします。今、私は属性付きのテキストにアクセスしようとしています。この一連のオブジェクトと配列の奥深くに埋もれています。

stdClass Object ( [id] => /m/09c7w0 [property] => stdClass Object ( [/common/topic/description] => stdClass Object ( [valuetype] => string [values] => Array ( [0] => stdClass Object ( [text] => The United States of America, commonly called the United States and colloquially referred to as... [lang] => en [creator] => /user/wikirecon_bot [project] => wikirecon [dataset] => /m/0kj4zz_ [citation] => stdClass Object

これは私がこれまでに試したことですが、いくつかのエラーが発生しています。$stuff =$data->property->/common/topic/description->text;

エラーが「/common/topic/description」の結果である可能性があることはわかっています。JSON応答をphpオブジェクトに変換する必要がありますか、それとも最初にjsonで値を見つけようとする必要がありますか? その属性「テキスト」にアクセスする方法はありますか

4

2 に答える 2

2

json_decode($jsonstring, true)テキストと数字のキーを持つ配列のみを取得し、オブジェクトを取得しないために使用してください。

そうすれば、すべてに簡単にアクセスできます。キーの命名方法に対する制限も少なくなります。

于 2013-03-27T23:23:08.240 に答える
0

クラスと配列の混合物を読むのは少し難しいですが、これを試してください:

$data->property->{'/common/topic/description'}->values[0]->text

于 2013-03-27T23:20:16.857 に答える