我的代码参考
var sample = DataContractDeserializeObject<MySample>(
"<MySample xmlns=\"http://schemas.datacontract.org/2004/07/Sample\"><Charecter>'D'</Charecter></MySample>");
When i run this code. i get this message "There was an error deserializing the object of type MySample. Content cannot be converted to the type Int. Line 1, position 129."
我的反序列化代码
public static T DataContractDeserializeObject<T>(string objectToDeserialize)
{
using (XmlReader reader = XmlReader.Create(new StringReader(objectToDeserialize)))
{
var serializer =
new DataContractSerializer(typeof(T));
return (T)serializer.ReadObject(reader);
}
}
我的数据合同
[DataContract]
public class MySample
{
[DataMember]
public char Charecter { get; set; }
}
如何反序列化 char。谢谢。