Dan
Dan

Reputation: 61

How to deserialise PHP Serialized array in C#

I've got an array string serialised via PHP (Wordpress) similar to the following:

a:2:{i:0;s:12:"Sample array";i:1;a:2:{i:0;s:5:"Apple";i:1;s:6:"Orange";}}

How would I deserialise this string in C#?

If I paste the string into https://www.unserialize.com, it converts the structure fine.

Thanks!

Upvotes: 5

Views: 1553

Answers (1)

Sabrina
Sabrina

Reputation: 2799

You can use KaitaiStruct library.

Example(source):

// Parse a local file and get structure in memory
var data = PhpSerializedValue.FromFile("path/to/local/file.php_serialized_value");

Upvotes: 2

Related Questions