I get this error when using my class.
Error
Waiting for the root element from the namespace ''. Encounted 'None' with name '', namespace
My class
[DataContract] public class EntryData { [DataMember] public string EntryId { get; set; } [DataMember] public string EmailAddress { get; set; } [DataMember] public string StatusCode { get; set; } [DataMember] public string TotalVoteCount { get; set; } public static T Deserialise<T>(string json) { var obj = Activator.CreateInstance<T>(); using (var memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(json))) { memoryStream.Position = 0; var serializer = new DataContractJsonSerializer(obj.GetType()); obj = (T)serializer.ReadObject(memoryStream);
USING
string responseJson = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd(); var results = EntryData.Deserialise<EntryData>(response)
I saw online that it has to memoryStream position with the memoryStream position BUT, as you can see that I am setting it to the beginning.
Please, help.
Json goes to handler
I do not set StatusCode or TotalVoteCount when passing JSON. I do not think this is a problem.
{ "EntryId":"43", "EmailAddress":" test@email.com " }
ANSWER
Instead of using the Deserialize method in my class, I use this now.
source share