我有以下XML
:意外的節點類型元素
<Envelope>
<Body>
<RESULT>
<SUCCESS>TRUE</SUCCESS>
<RecipientId></RecipientId>
<ORGANIZATION_ID>12345-67890-b9e6bcd68d4fb511170ab3fcff55179d</ORGANIZATION_ID>
</RESULT>
</Body>
</Envelope>
我敢嘗試反序列化到:
[XmlRoot(ElementName = "Envelope")]
public class Add_Recipent_response
{
public string Body { get; set; }
public string RESULT { get; set; }
public string SUCCESS { get; set; }
public string RecipientId { get; set; }
public string ORGANIZATION_ID { get; set; }
}
使用這種方法:
protected void deserializeXML(string xmlResponse)
{
XmlSerializer deserializer = new XmlSerializer(typeof(Add_Recipent_response));
using (TextReader reader = new StringReader(xmlResponse))
{
try
{
Add_Recipent_response XmlData = (Add_Recipent_response)deserializer.Deserialize(reader);
}
catch (Exception ex)
{
Console.WriteLine(ex.GetBaseException());
}
}
}
這將引發例外:
InnerException = {"Unexpected node type Element. ReadElementString method can only be called on elements with simple or empty content. Line 4, position 2."}
誰能告訴我什麼,我做錯了什麼?
東西,你可以使用Visual Studio的https://msdn.microsoft.com/en-us/library/hh371548(v=vs.110).aspx – suphero 2015-10-23 17:54:40