DataContractJsonSerializer exception
Could it be caused by your JSON names not matching your property names in C#?
My understanding is that
{ "FirstName" : "Mark"}
Would be able to deserialize into:
[DataContract]public class Person { [DataMember] public string FirstName {get; set;}}
but this wouldn't be able to serialize
{ "Name" : "Mark"}
unless you changed your C# class to have an explicit name for the DataMember
[DataContract]public class Person { [DataMember(Name="Name")] public string FirstName {get; set;}}
I'm not sure which error this would cause though. I Don't have enough first hand experience.
Do you think it could be an encoding problem? Have you tried using Encoding.UTF8 instead of Unicode?
All the examples I have seen using DataContractSerializer have used a UTF-8 encoding.
Encoding.Unicode is a UTF-16 encoding.
I can't find any documentation explicitly stating which encodings DataContractSerializer supports. I assume it would be smart enough to detect the proper encoding, but I don't know a whole whole lot about encodings. Maybe that isn't really possible in this instance.