我有一个这样的XML字符串:
<?xml version="1.0" ?>
<result>
<vmeet_id>7121</vmeet_id>
<username>MT_Hue_QuangBinh_QuangTri</username>
<email></email>
<begin_date>2010-04-21 08:53</begin_date>
<expiry_date>2010-12-21 00:00</expiry_date>
<point></point>
<info>OK</info>
</result>
我想将它反序列化为一个对象,因此我创建了这个类:
[Serializable]
[XmlRoot(ElementName = "result", IsNullable = false)]
public class UserInfo
{
[XmlAttribute("vmeet_id")]
public int UserID { get; set; }
[XmlAttribute("username")]
public string Username { get; set; }
[XmlAttribute("email")]
public string Email { get; set; }
[XmlAttribute("begin_date")]
public DateTime BeginDate { get; set; }
[XmlAttribute("expiry_date")]
public DateTime ExpiryDate { get; set; }
[XmlAttribute("point")]
public string Point { get; set; }
[XmlAttribute("info")]
public string Info { get; set; }
}
然后使用此代码反序列化:
var deserializer = new XmlSerializer(typeof(UserInfo));
using (var stream = new StringReader(result))
{
UserInfo userInfo = (UserInfo)deserializer.Deserialize(stream);
return userInfo;
}
返回值不是空值,但其所有属性都是空值:
<result vmeet_id="0" begin_date="0001-01-01T00:00:00" expiry_date="0001-01-01T00:00:00"/>
这里怎么了?我忘记什么了吗?
谢谢您。