0

https://graph.facebook.com/search?q=India&type=post i am using the above api of Facebook and i am getting following Output

{
   "data": [
      {
         "id": "501585456_163489377008878",
         "from": {
            "name": "Ian Robinson",
            "id": "501585456"
         },
         "message": "\"Media subdues the public\".  Noam Chomsky still firing http://www.outlookindia.com/article.aspx?267553",
         "picture": "http://external.ak.fbcdn.net/safe_image.php?d=c6a004d1d5a2ba4cb419ae93c26b2b1f&w=90&h=90&url=http%3A%2F%2Fphoto.outlookindia.com%2Fimages%2Fgallery%2F20101020%2Fnoam_chomsky_20101101.jpg",
         "link": "http://outlookindia.com/article.aspx?267553",
         "name": "www.outlookindia.com | \u201cMedia Subdues The Public. It\u2019s So In India, Certainly\u201d",
         "caption": "outlookindia.com",
         "description": "Noam Chomsky has a veritable cult following among those who are sceptical about views the liberal media espouses and government propaganda machinery spawns to suit their often overlapping agendas. Compelling is his criticism, breathtaking is his knowledge, persuasive is his voice, and deep runs his ",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/zD/r/aS8ecmYRys0.gif",
         "type": "link",
         "created_time": "2010-10-24T13:44:01+0000",
         "updated_time": "2010-10-24T13:44:01+0000"
      },

How can we convert it into php and get following output

Name:Ian Robinson
Description:

1 Answer 1

3

Update

$array = json_decode($your_json_data, true);
echo $array['data']['id'];
echo $array['data']['message'];
echo $array['data']['description'];
// and so on

You can use the json_decode() function and treat it like normal array.

json_decode — Decodes a JSON string

Example:

 var_dump(json_decode($json, true));
Sign up to request clarification or add additional context in comments.

2 Comments

how we will get the file content??
@Alex Mathew: I have updated the answer but you should be able to decipher that after seeing the exact output of the array with ` var_dump(json_decode($json, true));`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.