Json Serializer - CSharp System.Runtime.Serialization.Json

CSharp examples for System.Runtime.Serialization.Json:Json

Description

Json Serializer

Demo Code


using System.Runtime.Serialization.Json;
using System.Collections.Generic;
using System.Text;
using System.IO;/*w w w .j a va 2 s  .  c  o m*/
using System;

public class Main{

        public static string JsonSerializer<T>(T t)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
            MemoryStream ms = new MemoryStream();
            ser.WriteObject(ms, t);
            string jsonString = Encoding.UTF8.GetString(ms.ToArray());
            ms.Close();
            return jsonString;
        }
}

Related Tutorials