Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Posts
    199
    Thanks
    78
    Thanked 5 Times in 5 Posts

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

    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.

    Code:
    Catchable fatal error: Object of class stdClass could not be converted to string
    Here is my php code:
    PHP Code:
    <?php

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

    foreach (
    $item as $row) { 
        echo 
    $row->title;
    }
    ?>
    Last edited by conware; 11-25-2011 at 12:27 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • Users who have thanked Fou-Lu for this post:

    conware (11-25-2011)

  • #3
    Regular Coder
    Join Date
    Mar 2010
    Posts
    199
    Thanks
    78
    Thanked 5 Times in 5 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •