madziikoy
madziikoy

Reputation: 1497

Facebook JSON array

How do I display the data->name?

{
   "data": [
      {
         "name": "Aasdada",
         "category": "asdasd",
         "id": "2342342342",
         "created_time": "2012-11-28T03:56:00+0000"
      }
   ],
   "paging": {
      "next": "https://graph.facebook.com/&limit=5000&offset=5000&__after_id=12312"
   }
}

I tried this but nothing comes out:

$user = json_decode(file_get_contents($graph_url), true);
echo("Hello " . $user->data->name);

//also tried this
echo("Hello " . $user[data]); //did not echo anything
echo("Hello " . $user->data[0]->name); //did not echo anything

$user->data[0]['name'] //still no luck

What could be the problem? Anyways my code works with data that is not in array.

I'm just trying to make a simple if user liked page or not. If data has no contents it means the user has not liked the page. If it has data then it means the user has liked the page.

--edit--

So tried this out:

array(2) { ["data"]=> array(1) { [0]=> array(4) { ["name"]=> string(28) "Aasdda" ["category"]=> string(5) "asdad" ["id"]=> string(15) "3123123123" ["created_time"]=> string(24) "2012-11-28T03:56:00+0000" } } ["paging"]=> array(1) { ["next"]=> string(245) "https://graph.facebook.com/100023123123" } }

Upvotes: 1

Views: 349

Answers (2)

sinisterfrog
sinisterfrog

Reputation: 536

Try:

$user['data']['0']['name']

Upvotes: 2

JPR
JPR

Reputation: 869

Try:

 $user->data[0]['name']

Upvotes: 0

Related Questions