所以我有这个 XML 字符串:
<?xml version="1.0" encoding="utf-16"?>
<options>
<option category="Fabric" descriptiveName="BLUSH" grade="B">
<optionProductID category="cover">
<id optionIDQualifier="SellerAssigned" optionID="BLUSH" />
</optionProductID>
<optionQuantity unitOfMeasure="Each" value="1" />
<optionPrice>899</optionPrice>
<optionRetailPrice>899</optionRetailPrice>
<sequenceNumber>0</sequenceNumber>
<areaName>BODY</areaName>
<areaCode />
</option>
<option category="Fabric" descriptiveName="597" grade="B">
<optionProductID category="cover">
<id optionIDQualifier="SellerAssigned" optionID="597" />
</optionProductID>
<optionQuantity unitOfMeasure="Each" value="1" />
<optionPrice>20</optionPrice>
<optionRetailPrice>20</optionRetailPrice>
<sequenceNumber>0</sequenceNumber>
<areaName>BACK CUSHION WELT</areaName>
<areaCode />
</option>
</options>
我创建了这些类:
public class options
{
public List<option> option { get; set; }
}
public class option
{
[System.Xml.Serialization.XmlAttribute]
public string category { get; set; }
[System.Xml.Serialization.XmlAttribute]
public string descriptiveName { get; set; }
[System.Xml.Serialization.XmlAttribute]
public string grade { get; set; }
public string optionPrice { get; set; }
public string areaName { get; set; }
}
我尝试像这样反序列化它:
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(options));
System.IO.StringReader rdr = new System.IO.StringReader(xmlstring);
options resultingMessage = (options)serializer.Deserialize(rdr);
我需要将此 XML 字符串反序列化到此类中,但一直遇到问题,我在这里做错了什么?
目前我收到此错误:
<option xmlns=''> was not expected.