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.

2
  • Nowhere are you parsing the data you get back. Commented Dec 14, 2012 at 1:19
  • Thanks Mario, But i have no idea of What is a Json string. :( Commented Dec 14, 2012 at 1:22

1 Answer 1

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().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.