0
Twitter APIを使用していて、JSON出力を解析しようとしています。しかし、どういうわけか私は間違ったことをやっているし、私は何をしたいのか分からない。解析されたJSON出力からオブジェクトを取得する際に問題が発生しました
この場合、私はPHPで書いています。配列のループを開始し、screen_nameとtextがそれに応じて動作します。
foreach ($statuses as $obj) {
$screen_name = filter_var($obj->user->screen_name, FILTER_SANITIZE_STRING);
$text = filter_var($obj->text, FILTER_SANITIZE_STRING);
$urls = filter_var($obj->entities->urls->url, FILTER_SANITIZE_URL);
}
JSON配列出力:urls
以来
array (
0 =>
stdClass::__set_state(array(
'created_at' => 'Fri Oct 07 15:31:01 +0000 2016',
'text' => 'test',
'entities' =>
stdClass::__set_state(array(
'hashtags' =>
array (
0 =>
stdClass::__set_state(array(
'text' => '30Under30',
'indices' =>
array (
0 => 36,
1 => 46,
),
)),
),
'symbols' =>
array (
),
'user_mentions' =>
array (
),
'urls' =>
array (
0 =>
stdClass::__set_state(array(
'url' => 'https://Forbes.com',
'expanded_url' => 'https://twitter.com/i/web/status/784415744427687936',
'display_url' => 'twitter.com/i/web/status/7…',
'indices' =>
array (
0 => 117,
1 => 140,
),
)),
),
)),
'source' => 'Sprinklr',
'in_reply_to_screen_name' => NULL,
'user' =>
stdClass::__set_state(array(
'id' => 91478624,
'screen_name' => 'test',
'url' => 'http://Forbes.com',
'entities' =>
stdClass::__set_state(array(
'url' =>
stdClass::__set_state(array(
'urls' =>
array (
0 =>
stdClass::__set_state(array(
'url' => 'http://Forbes.com',
'expanded_url' => 'http://forbes.com',
'display_url' => 'forbes.com',
'indices' =>
array (
0 => 0,
1 => 22,
),
)),
),
)),
'description' =>
stdClass::__set_state(array(
'urls' =>
array (
0 =>
stdClass::__set_state(array(
'url' => 'http://Forbes.com',
'expanded_url' => 'http://Forbes.com',
'display_url' => 'Forbes.com',
'indices' =>
array (
0 => 28,
1 => 48,
),
)),
),
)),
)),
'protected' => false,
'notifications' => false,
)),
'geo' => NULL,
'lang' => 'en',
)),
)
あなたが結果として欲しいものの例を持っているとよいでしょう。私の推測では、真の 'json_decode($ string、true)'として2番目のパラメータを渡すだけです。 http://php.net/manual/en/function.json-decode.php –
最初の ''url' => 'https:// Forbes.com'、'パラメータが必要です。私は32行目だと思う。私にはパスはentities-> urls-> urlのようだ。しかし、これは動作しません – RvdM
'urls'は配列なので、' $ obj-> entities-> urls [0] - > url' – Barmar