DataContractJsonSerializer Demo
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Runtime.Serialization;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
public static class Common
{
public static string Serialize<T>(this object collection)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(collection.GetType());
using (MemoryStream s = new MemoryStream())
{
serializer.WriteObject(s, collection);
return Encoding.UTF8.GetString(s.GetBuffer());
}
}
}
Related examples in the same category