public static string ObjToJson <T>(VoteItem data) { try { System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(data.GetType()); using (MemoryStream ms = new MemoryStream()) { serializer.WriteObject(ms, data); return(Encoding.UTF8.GetString(ms.ToArray())); } } catch { return(null); } }