简体   繁体   中英

How to echo a JSON output

Below is the JSON code i got after logging in with Facebook. How can extract data from this JSON ? I tried the following ones, but not working.

$user = json_decode(file_get_contents($graph_url));

stdClass Object ( [id] => 725426940865193 [email] => stargijo2@gmail.com [first_name] => Gijo [gender] => male [last_name] => Varghese [link] => https://www.facebook.com/app_scoped_user_id/725426940865193/ [locale] => en_GB [name] => Gijo Varghese [timezone] => 5.5 [updated_time] => 2014-09-27T13:47:05+0000 [verified] => 1 ) 

echo $user['email']; //not working

It's an object , not an array. You need to use object syntax:

echo $user->email;

If you want to access it as an array you must pass true as the second parameter to json_decode() :

$user = json_decode(file_get_contents($graph_url), true);
echo $user['email'];

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