...

View Full Version : Resolved Catchable fatal error: Object of class stdClass could not be converted to string



conware
11-24-2011, 07:38 PM
Hi guys I was trying to get my latest youtube video info with json.
Only I have run into a problem i'm not really sure how I can echo it out.
Everytime I try I get the following error message.



Catchable fatal error: Object of class stdClass could not be converted to string


Here is my php code:


<?php

$jsonurl = 'http://gdata.youtube.com/feeds/base/users/NintendoWizard22/uploads?alt=json&v=2';
$json = file_get_contents($jsonurl, 0, null, null);
$json_output = json_decode($json);
$item = $json_output->feed->entry;

foreach ($item as $row) {
echo $row->title;
}
?>

Fou-Lu
11-24-2011, 09:23 PM
This error indicates that the $row->title returns a type of object which doesn't override the __toString method. That means that $row->title is not a string as you may expect, rather it is an object. You can determine what properties it has and its class type by using an evaluation print instead such as var_dump.

conware
11-25-2011, 12:27 AM
Hi Fou-Lu,

I never really use objects so i'm not really familiar how the operate.
However I found out that json_decode has a second option when TRUE, the returned objects will be converted into associative arrays.
I think i'll use that, sins its a bit easier for me to work with.

Thanks for the info btw about var_dump.
I'll keep that one in mind while i continue learning about php objects.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum