0

Possible Duplicate:
json decode in php

I want to get my id in php, actually without that php sdk files. So i am using this.

$a = file_get_contents('https://graph.facebook.com/100004304380055...');
echo $a['id'];

The contents of the response are

{
    "id": "100004304380055",
    "name": "Ayush Mishra"
}

But it does not returns my id 100004304380055. I thing $a is not an array. I want to know how to make $a an array and then get my id by $a['id']. Please provide the code. Any help will be appreciated.

Community
  • 1
  • 1

1 Answers1

2

The endpoint is returning a JSON string; which is a format used to convey object information as a string. Convert the string back to an object, and grab the id property:

$data = json_decode($response);
echo $data->id;

Where $response is the result of your call to file_get_contents().

Sampson
  • 265,109
  • 74
  • 539
  • 565