c# - XML 反序列化为嵌套的对象数组。再次
问题描述
我正在从 Web 服务获取一些 XML。我建立了一些类来反序列化它。它部分工作;AdvMortgage
我得到了对象原始成员的预期值。
Mortgage
正如代码所示,我得到了any 字段的空值AdvMortgage
。这与我最近发布的问题类似,但我确实遇到了麻烦。我究竟做错了什么?
<Product xmlns="http://schemas.datacontract.org/2004/07/mInitechService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
...
<AdvMortgage>
<Mortage>
<MortgageType>...</MortgageType>
<MortgageType>...</MortgageType>
<MortgageType>
<apr>4.99</apr>
<discountPts>0.00</discountPts>
<originationFee>0.00</originationFee>
<pgmName>7/1 Adjustable</pgmName>
<rate>4.875</rate>
</MortgageType>
</Mortage>
<mortEffectiveDate>Rates effective 12/4/2018</mortEffectiveDate>
<mortNote>
ARM = Adjustable Rate Mortgage
...
</mortNote>
</AdvMortgage>
...
<effectiveDate>Rates effective from 12/01/2018 through 12/31/2018</effectiveDate>
</Product>
和课程:
namespace InitechServiceEntities
{
[XmlType(AnonymousType = true, Namespace = "http://schemas.datacontract.org/2004/07/mInitechService")]
[XmlRoot(Namespace = "http://schemas.datacontract.org/2004/07/mInitechService", IsNullable = false)]
public class Product
{
//...
[XmlElement("AdvMortgage")]
public AdvMortgage AdvMortgage;
[XmlElement("effectiveDate")]
public string effectiveDate;
}
[XmlType("AdvMortgage")]
public class AdvMortgage
{
[XmlElement("mortEffectiveDate")]
public string mortEffectiveDate;
[XmlElement("mortNote")]
public string mortNote;
[XmlArray(ElementName = "Mortgage")]
[XmlArrayItem(Type = typeof(MortgageType))]
public MortgageType[] Mortgage;
}
[XmlType("MortgageType")]
public class MortgageType
{
[XmlElement("pgmName")]
public string pgmName;
[XmlElement("rate")]
public string rate;
[XmlElement("apr")]
public string apr;
[XmlElement("discountPts")]
public string discountPts;
[XmlElement("originationFee")]
public string originationFee;
}
}
解决方案
grek40,er-shoaib,谢谢。我一直盯着它看了那么久,我从来没有意识到写服务的人拼错了“抵押贷款”。我需要休假。
推荐阅读
- java - 自动完成硒
- docker - Dock Run 不生成容器
- python - 如何在python的simplewebsocketserver中给出IP地址
- java - 无法使用 mockito 模拟来自 Mapper 类的数据
- php - Nested php foreach in MVC
- java - java spring如何自定义@NotNull验证报错信息
- java - 在 Tomcat 中部署 WAR 文件(路径)
- ios - Flutter 不断为 iOS 导入旧版本的 Plugin
- android - Eclipse 不支持 SDK layoutlib 版本
- mongodb - MongoDB:查找后的操作需要很长时间