I have a XML string like that:
<?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>
I want to deserialize it into an object, so I created this class:
[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; }
}
and then use this code to deserialize:
var deserializer = new XmlSerializer(typeof(UserInfo));
using (var stream = new StringReader(result))
{
UserInfo userInfo = (UserInfo)deserializer.Deserialize(stream);
return userInfo;
}
return value was not null, but all its properties was null value:
<result vmeet_id="0" begin_date="0001-01-01T00:00:00" expiry_date="0001-01-01T00:00:00"/>
what is wrong here? Did I forgot something?
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…