Jump to content

Retain custom object with json_encode()


victorsk

Recommended Posts

Hi everyone,

 

I've got a custom Web_Services_Object object which I am trying to encode with json_encode(), store it in MySQL DB, then json_decode() back to use it.  The problem is that after applying json_decode(), this object becomes stdClass and it must be Web_Services_Object type.  Here is a snapshot of what I have:

 

$client = new Web_Services_Object;
$client->CallAPI();
$obj = json_encode($client);

 

 

After json_decode($obj) is done, I get stdClass Object for:

 

$myObj =  json_decode($obj); //is stdClass 

 

But I need it to be of type Web_Services_Object.  Please, I am not very knowledgeable with PHP, could you please provide an example how this could be done?  I think it has something to do with serializing object but I have no idea how to implement it.

 

Thank you,

Victor.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.