【发布时间】:2015-10-17 08:33:24
【问题描述】:
我正在尝试使用此 XML 反序列化字符串 response.Content
<?xml version="1.0" encoding="utf-8"?><root><uri><![CDATA[http://api.bart.gov/api/stn.aspx?cmd=stns]]></uri><stations><station><name>12th St. Oakland City Center</name><abbr>12TH</abbr><gtfs_latitude>37.803664</gtfs_latitude><gtfs_longitude>-122.271604</gtfs_longitude><address>1245 Broadway</address><city>Oakland</city><county>alameda</county><state>CA</state><zipcode>94612</zipcode></station>
我正在使用这段代码来反序列化它:
var serializer = new XmlSerializer(typeof(Stations), new XmlRootAttribute("root"));
Stations result;
using (TextReader reader = new StringReader(response.Content))
{
result = (Stations)serializer.Deserialize(reader);
}
然后我在这里声明了Stations 类
[XmlRoot]
public class Stations
{
[XmlElement]
public string name;
}
但是,我的name 为空。知道为什么吗?
【问题讨论】:
-
查看这篇文章,了解你正在尝试做的事情的一个很好的例子stackoverflow.com/questions/364253/…
标签: c# .net xml xml-deserialization