Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Deserialisation in C#

Posted on 2014-03-24
4
Medium Priority
?
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 750 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 111

Accepted Solution

by:
Ray Paseur earned 750 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 111

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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Progress

705 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