Solved

Deserialisation in C#

Posted on 2014-03-24
4
168 Views
Last Modified: 2014-03-24
Hi all,

I was wondering if anyone can please advise. Basically I'm using memcache. The idea is that a php systems serialises an object and puts it on the memcache. I then retrieve it in my C# project and de-serialises it.

I cant see any of the php side of it and should be just able to de-serialise it. The data I have is like this.

SESSION_STUFF|a:1:{i:-1;s:0:"";}

Apparently above is already serialised. So I need to get it into a memory stream and de-serialise as above.

Any advice would be really appreciated. This is one of the toughest tests I have faced.

Thanks in advance.
0
Comment
Question by:meetsys
  • 2
4 Comments
 
LVL 21

Expert Comment

by:Dale Burrell
ID: 39949817
The problem is that you can serialise an object in many different ways, its not like there is one way to do it. Therefore you have to know how PHP serialises an object to be able to deserialise it.

However with a bit of a google search it appears someone has already solved the problem for you: http://sourceforge.net/projects/csphpserial/
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 39949822
that data looks like JSON encoded data:
http://en.wikipedia.org/wiki/JSON
so, you use the DataContractJsonSerializer  class:
http://msdn.microsoft.com/en-us/library/bb412179%28v=vs.110%29.aspx
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39949968
Rather than serializing an object with PHP serialize() you want to json_encode() the object.  The results is still a data string that represents an object, but the advantage of the JSON string is that it is a widely supported format that plays well outside of PHP, making sense to other programming lanugages, JavaScript, etc.

See also this cautionary tale.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39950150
Hi, meetsys.  I see you are new to Experts-Exchange.  The community standards incorporate the grading guidelines.  If you were unhappy with the answers, you're expected to engage in dialog with the Expert community to satisfy your issues.  If you were happy with the answers, the correct (and default) grade is "A."

http://support.experts-exchange.com/customer/portal/articles/481419

Please let us know if you didn't understand the answer or if we let you down in some way.  Thanks. ~Ray
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now