Post your own serialized code:
public class Xmlutil {//<summary>//XML & DataContract Serialize & Deserialize Helper </summary>//<typeparam name= "T" ></typeparam>//<param name= "Serialobjec T "></param>///<returns></returns> public static string serializer<t> (t Serialob ject) where T:class {string result = string. Empty; using (MemoryStream mem = new MemoryStream ()) {using (XmlTextWriter writer = new XmlTextWriter ( MEM, Encoding.UTF8)) {System.Xml.Serialization.XmlSerializer ser = new System.Xml.Seria Lization. XmlSerializer (typeof (T)); Ser. Serialize (writer, serialobject); result = Encoding.UTF8.GetString (mem. ToArray ()); }} return result; } public static T deserialize<t> (String str) where T:class { T result = null; using (MemoryStream MemoryStream = new MemoryStream (Encoding.UTF8.GetBytes (str))) {using (Strea Mreader StreamReader = new StreamReader (MemoryStream)) {System.Xml.Serialization.XmlSer Ializer XmlSerializer = new System.Xml.Serialization.XmlSerializer (typeof (T)); result = (T) xmlserializer.deserialize (MemoryStream); }} return result; } }
The above notation will not have memory overflow performance problem, has been told to refer directly to the company of an old bird packaged dll to serialize, and later found that there is always a memory overflow, paste the wrong way of writing, only for lessons learned:
public class Xmlutil {//<summary>//XML & DataContract Serialize & Deserialize Helper </summary>//<typeparam name= "T" ></typeparam>//<param name= "Serialobjec T "></param>///<returns></returns> public static string serializer<t> (t Serialob ject) where T:class {//try//{XmlSerializer ser = new XmlSerializer (typeof (T)) ; System.IO.MemoryStream mem = new MemoryStream (); XmlTextWriter writer = new XmlTextWriter (mem, Encoding.UTF8); Ser. Serialize (writer, serialobject); Writer. Close (); Return Encoding.UTF8.GetString (Mem. ToArray ()); }//catch (Exception ex)//{//return null; }} public static T deserialize<t> (String str) where T:class {//try {XmLserializer myserializer = new XmlSerializer (typeof (T)); StreamReader mem2 = new StreamReader (New MemoryStream (System.Text.Encoding.UTF8.GetBytes (str)), SYSTEM.TEXT.ENCODING.UTF8); Return (T) myserializer.deserialize (MEM2); }//catch (Exception)//{//return null; }}//public static string Json_serializeobject (object value)//{//Return Newtonsoft.js On. Jsonconvert.serializeobject (value); }//public Static Object Json_deserializeobject (string value)//{//Return Newtonsoft.Json.Json Convert.deserializeobject (value); }//public static T json_deserializeobject<t> (string value)//{//Return Newtonsoft.json. Jsonconvert.deserializeobject<t> (value); //} }