我在反序列化 XML 时遇到问题:
[XmlRoot("ProductCategory")]
public class ProductCategory
{
public Product[] Products;
}
public class Product
{
[XmlArray("Product")]
[XmlArrayItem("ProductPrice", typeof(ProductPrice))]
public ProductPrice[] Prices;
}
public class ProductPrice
{
[XmlAttribute]
public int Duration;
[XmlAttribute]
public string DurationType;
[XmlAttribute]
public decimal Price;
[XmlAttribute]
public decimal RegularPrice;
[XmlAttribute]
public decimal YourPrice;
[XmlAttribute]
public string CouponPrice;
[XmlAttribute]
public string Currency;
}
这是行动:
public ProductType GetPricing()
{
XDocument doc = new Query(_params)
.AddParameter("ProductType", "DOMAIN")
.AddParameter("ActionName","REGISTER")
.Execute("namecheap.users.getPricing");
var serializer = new XmlSerializer(typeof(ProductType), _ns.NamespaceName);
using (var reader = doc.Root.Element(_ns + "CommandResponse").Element(_ns + "ProductType").CreateReader())
{
return (ProductType)serializer.Deserialize(reader);
}
}
我收到此错误: NullReferenceException:未将对象引用设置为对象的实例。
在这里您可以找到 xml 的示例:https ://www.namecheap.com/support/api/methods/users/get-pricing.aspx
有任何想法吗?