简体   繁体   中英

PHP decoding json and display it

I need to decode a json file and display it in the page.. My code is not working, and i don't know whats wrong. The output is just a blank page.

Here is the json file. .

{
   "data": [
      {
         "name": "Jhaimee",
         "uid": 10000
      },
      {
         "name": "Ally",
         "uid": 10000133
      },
      {
         "name": "Macers",
         "uid": 1000056
      },
      {
         "name": "Diego",
         "uid": 100004
      },
      {
         "name": "Killersmile",
         "uid": 1000050
      },
      {
         "name": "Joel",
         "uid": 1000011
      }
   ]
}

I want the output to be..

Jhaimee
Ally
Macers
Diego
Killersmile
Joel

Here is my php.

$data = file_get_contents("https://graph.facebook.com/fql?q=SELECT name,uid FROM user WHERE uid IN  (SELECT  recipients FROM thread WHERE folder_id = 0 ORDER BY message_count DESC) AND uid != me() LIMIT 10&access_token=xxxx");
$data = json_decode($data, true);
echo $data[0]["name"];

The outermost array key should be data echo $data['data'][0]['name'] foreach($data['data'] as $person){ echo $person['name'] . "<br />\\n"; } foreach($data['data'] as $person){ echo $person['name'] . "<br />\\n"; }

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