How to Deserialize string returned by webservice to an object in C#(CSharp)

public static T Deserialize<T>(string data)
	T result;
	XmlSerializer xSer = new XmlSerializer(typeof(T));
	using (StringReader sr = new StringReader(data))
		result = (T)xSer.Deserialize(sr);
	return result;

Using it:

string result = "<?xml 1.0 ... <person><site></site></person>..."; //returned from web service
person p = Deserialize<person>(result);

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.