Json Deserialize - CSharp System.Runtime.Serialization.Json

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

Description

Json Deserialize

Demo Code


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

public class Main{

        public static T JsonDeserialize<T>(string jsonString)
        {
            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
            T obj = (T)ser.ReadObject(ms);
            return obj;
        }
}

Related Tutorials