Solved

Deserialisation in C#

Posted on 2014-03-24
4
169 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn how to dynamically set the form action using jQuery.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

16 Experts available now in Live!

Get 1:1 Help Now