简体   繁体   中英

decoding json array object response

I already checked previous all thread but no luck.

I am getting json response like this: http://pastebin.com/HS0UhYat for var_dump($tweets5);

code:

//$tweetid = "200582436";
$tweets5 = $connection->get("https://api.twitter.com/1.1/statuses/retweets/".$tweetid.".json?count=1");
var_dump($tweets5);
$tweets5 = json_decode($tweets5,true);
echo $tweets5[retweeted_status][user][name];
echo $tweets5->retweeted_status->user->name;
echo "$tweets5<br><br>";

I want to get each value username, id etc seperately. how to to this?

you can use a simple foreach on your json object:

foreach($tweets5[0] as $tweet) {
    echo $tweet['user']['name'];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM