SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    127
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    when does json_decode doesn't work as object?

    I learned that

    PHP Code:
    json_decode($userinfo); 
    will decode the json string as object

    PHP Code:
    json_decode($userinfotrue); 
    will decode the json string as array..

    For some reason I'm able to extract the json string as array but when I try it to do it as object it breaks. Do you have any idea why?

    Thanks

  2. #2
    SitePoint Zealot ameerulislam's Avatar
    Join Date
    Jul 2011
    Posts
    127
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ameerulislam View Post
    I learned that

    PHP Code:
    json_decode($userinfo); 
    will decode the json string as object

    PHP Code:
    json_decode($userinfotrue); 
    will decode the json string as array..

    For some reason I'm able to extract the json string as array but when I try it to do it as object it breaks. Do you have any idea why?

    Thanks
    crap!! the problem was that I was putting echo in front of it when it was an object
    PHP Code:
    echo $userinfo json_decode($userinfo); 
    but this works when it's an array.. like
    PHP Code:
    echo $userinfo json_decode($userinfotrue); 
    it prints Array..

    It would be great if the first one printed object or something instead of breaking down..


Bookmarks

Posting Permissions

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