Generic function to deserialize json string RRS feed

  • Question

  • Hi All , 

    I need a common function to deserialize a json response to object 

    Happy Coding Syam.S

    Tuesday, May 29, 2012 6:31 AM


  • Hi Syam, 

    You can create a generic function for this purpose use code below, the function will return object of given type.

     public static T Deserialize<T>(string jsonString)
                     using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)))
                         DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
                         return (T)serializer.ReadObject(ms);

    Detailed description is found Click here
    Tuesday, May 29, 2012 7:01 AM

All replies