0

I have a Json data retrieved from facebook using graph api, now i am going to parse that data, i decoded that json

$decodedjson= json_decode($jsondata);

after that i got data in following format. Image for Json data

i write

$id= $decodedjson->message_id;

to get the id, the attachment is an other object, please tell me how can i access the attachment, media, href, alt and the video , display_url and so on, name etc

Thanks

1
  • If you have difficulty traveresing objects, have you considered using arrays instead? If you provide true for the second variable in json_decode($jsondata,true);, it returns an assoc array instead.
    – Niklas
    Commented Jun 22, 2011 at 8:18

2 Answers 2

2

Just like any object -

$vid=($decodedjson[2])->attachment->media[0];
$alt=$vid->alt;

Edit: Noticed the [2]=>... at the top of your var_dump

2
  • when i used it says Notice: Trying to get property of non-object in C:\wamp\www\display\index.php
    – Asghar
    Commented Jun 22, 2011 at 8:29
  • I've just noticed that this is a partial var_dump by the looks of it. If you're going to post a var dump, post the dump of the whole object - it looks like $decodedjson is in fact an array of objects based on the [2] =>... at the top... Commented Jun 24, 2011 at 3:31
0

json_decode - convert json format to php array You should access it as array

$id= $decodedjson[0]['message_id'];


 $attachment= $decodedjson[0]['attachment']['media'];//an array

$video= $decodedjson[0]['media'][0]['video']['owner'];
2
  • he's var_dumped it, it's clearly a stdClass, this answer doesn't add anything... Commented Jun 22, 2011 at 8:19
  • $id= $decodedjson[0]['message_id']; is not correct because message_id is object and it will be accessed using $decodedjson[0]->message_id;
    – Asghar
    Commented Jun 22, 2011 at 8:33

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.