Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unserialize PHP Serialized array/variable/class and return suitable object in C#

The goal is to unserialize a PHP serialized string and get sutable object in C#

Is there any way to make this possible in C#(.Net)?

To be more specific: We need to make an application which comunicates (Via HTTP) to specific website which returns the needed information. Fortunately/unfortunately we dont have permission to website so the data (array mostly) that is returned from website is PHP serialized.

like image 659
George Avatar asked Dec 16 '09 13:12

George


People also ask

How do I unserialize data in PHP?

PHP unserialize() Function$data = serialize(array("Red", "Green", "Blue")); echo $data . "<br>"; $test = unserialize($data);

How can I access serialized form data in PHP?

To get the POST values from serializeArray in PHP, use the serializeArray() method. The serializeArray( ) method serializes all forms and form elements like the . serialize() method but returns a JSON data structure for you to work with.

What is serialized PHP array?

Definition and Usage. The serialize() function converts a storable representation of a value. To serialize data means to convert a value to a sequence of bits, so that it can be stored in a file, a memory buffer, or transmitted across a network.

What is the Unserialized object?

The unserialize function converts from serialized data to actual data. By serializing data, an array or an object, we mean we convert the data to a plain text format. By unserializing the data, we convert it back to the PHP code. So if we serialize an object, we make it a plain text string.


2 Answers

I suppose using JSON as an intermediary step could be useful.

like image 69
Fabian Vilers Avatar answered Nov 15 '22 13:11

Fabian Vilers


You should probably write it to XML or JSON. You can construct your C# object back from the XML

Edit: Looks like there is already a XML serializer for PHP

like image 45
ram Avatar answered Nov 15 '22 13:11

ram