Similar Topics...
 |
JSON Serializer in .NET /// /// Helper JSON Serialization tools /// public static class JSONSerializationUtility { /// /// Serialize to JSON /// /// /// public static string Serialize(object @object) { string xml = null; using (MemoryStream stream1 = new MemoryStream()) { var ser = new DataContractJsonSerializer(@object.GetType()); ser.WriteObject(stream1, @object); stream1.Position = 0; using (StreamReader sr = new StreamReader(stream1)) { xml = sr.ReadToEnd(); sr.Close(); } stream1.Close(); } return xml; } /// /// Deserialize from JSON /// /// /// /// public static T Deserialize (string xml) { object result = null; using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(xml))) { var ser = new DataContractJsonSerializer(typeof(T)); result = ser.ReadObject(ms); ms.Close(); } return (T)result; } }
Created By: amos 4/7/2015 11:32:08 AM
|
|
|
|
|
|