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
https://forums.phpfreaks.com/topic/202259-retain-custom-object-with-json_encode/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.