我从服务器收到一个 XML 文件,其中包含许多元素和一个属性。
当尝试对 xml 进行序列化/反序列化时,所有元素都已正确序列化/反序列化,但属性除外。为什么会这样?
这是 XML 文件:
"<msg><msisdn>123456789</msisdn><sessionid>535232573</sessionid><phase>2</phase><request type=\"1\">*120*111#</request></msg>"
和班级:
[Serializable]
[XmlRoot(ElementName = "msg", Namespace = "")]
public class myClass
{
[XmlElement(ElementName = "msisdn")]
public string number = string.Empty;
[XmlElement(ElementName = "sessionid")]
public string sessionID = string.Empty;
[XmlAttribute(AttributeName = "type")]
public string requestType = string.Empty;
[XmlElement(ElementName = "request")]
public string request = string.Empty;
[XmlElement(ElementName = "phase")]
public string phase = string.Empty;
public override string ToString()
{
return number + " - " + sessionID;
}
}
谢谢你的帮助