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

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

2 Comments

when i used it says Notice: Trying to get property of non-object in C:\wamp\www\display\index.php
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...
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 Comments

he's var_dumped it, it's clearly a stdClass, this answer doesn't add anything...
$id= $decodedjson[0]['message_id']; is not correct because message_id is object and it will be accessed using $decodedjson[0]->message_id;

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.