when does json_decode unable to decode json string as object?

Discussion in 'PHP' started by ameerulislam43, Oct 12, 2013.

  1. #1
    json_decode($userinfo);
    PHP:
    will decode the json string as object

    json_decode($userinfo, true);
    PHP:
    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
     
    ameerulislam43, Oct 12, 2013 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    Do you have an example string on which that happens?
     
    ThePHPMaster, Oct 12, 2013 IP
  3. ameerulislam43

    ameerulislam43 Active Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #3
    Hi, I found out that putting echo in front of
    json_decode($userinfo); 
    PHP:
    forcing to break.. but doesn't cause any problem when it is
    json_decode($userinfo, true);
    PHP:
    which is an array.. Interesting find for me..
     
    ameerulislam43, Oct 12, 2013 IP