none
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

Answers

  • 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

    http://ishareidea.blogspot.in/2012/05/json-conversion.html
    Tuesday, May 29, 2012 7:01 AM

All replies