victorsk Posted May 19, 2010 Share Posted May 19, 2010 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 More sharing options...
trq Posted May 19, 2010 Share Posted May 19, 2010 Just serialize it. Json doesn't stand for Javascript object notation for nothing. Link to comment https://forums.phpfreaks.com/topic/202259-retain-custom-object-with-json_encode/#findComment-1060579 Share on other sites More sharing options...
victorsk Posted May 19, 2010 Author Share Posted May 19, 2010 Hi, I got it. What I was missing is to apply unserialize() on the object after that. Thanks, Victor. Link to comment https://forums.phpfreaks.com/topic/202259-retain-custom-object-with-json_encode/#findComment-1060593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.