DataContractJsonSerializer Demo : Json « Network « C# / C Sharp






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

1.JSON (JavaScript Object Notation) Utility Methods.
2.Creates a JSON graph of all of the field's client-side data
3.Serializes/Deserializes source into a JSON string.
4.Removes Json null objects from the serialized string and return a new string(Extention Method)
5.Json String To Byte Array