2

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"];
Jairus Holein
  • 53
  • 2
  • 12

1 Answers1

3

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

djheru
  • 3,525
  • 2
  • 20
  • 20
  • Is theres a way to display the names without using foreach? Just using echo? – Jairus Holein Oct 25 '14 at 05:52
  • You could use `echo print_r($data['data'], true);` just to dump the array out. To format it, though, you have to iterate through the array – djheru Oct 25 '14 at 05:56