Link to home
Start Free TrialLog in
Avatar of zattz
zattz

asked on

read a serialized php array in c#

How do you read a serialized php array in c#?
Avatar of prakash_prk
prakash_prk
Flag of India image

can you give us more details?

What is the data type of the array you want to serialize?

if possible can you post a sample of "Serialized string of that array"?
Avatar of Kalpan
Please try JSON serializer for this...or JS below in C#

JavaScriptSerializer serializer = new JavaScriptSerializer();
var output = seriaizer.Serialize(your_anon_object);


Please refer the attached code for Json

Hope this will help...

Thanks, Kalpan
var serializer = new DataContractJsonSerializer(thing.GetType());
var ms = new MemoryStream();
serializer.WriteObject(ms, thing);
var json = Encoding.Default.GetString(ms.ToArray());

Open in new window

Use the XMLSeralizer class if you are using the soap services with php..or to get  the XML file...

Please refer the below one...

http://msdn.microsoft.com/en-us/library/90c86ass(VS.71).aspx
Avatar of zattz
zattz

ASKER

I can't get that json deserializer to work.

This is an example of the string array serialized by php:

a:5:

{s:19:"interlinking_method";s:6:"random";s:19:"interlinking_source";s:5:"group";s:29:"interlinking_update_frequency";s:1:"9";s:22:"interlinking_min_links";s:1:"2";s:22:"interlinking_max_links";s:1:"7";
please use the following link...and refer the attached code...

You can do this by XML serializer to prepare the XML file with PHP and than deseralize in C#

http://www.devshed.com/c/a/PHP/Serializing-XML-With-PHP/1/

http://devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=236

Hope that would work for you...

thanks, Kalpan
// include class file
include("Serializer.php");
 
// create object
$serializer = new XML_Serializer();
 
// create array to be serialized
$xml = array ( "book" => array (
    "title" => "Oliver Twist", 
    "author" => "Charles Dickens"));
 
// perform serialization
$result = $serializer->serialize($xml);
 
// check result code and display XML if success
if($result === true) 
{
 echo $serializer->getSerializedData();
}



//////////////////////////////////////////////////

// Deserialization
ShoppingList newList;
TextReader r = new StreamReader( "list.xml" );
newList = (ShoppingList)s.Deserialize( r );
r.Close();

Open in new window

Avatar of zattz

ASKER

Unfortunatly I don't have access to the php code. I am retrieving the array from a database.
ASKER CERTIFIED SOLUTION
Avatar of Gene_Cyp
Gene_Cyp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Zattz have you tried implementing this yet?
Avatar of zattz

ASKER

Many thanks