gpt4 book ai didi

c# - 意外的节点类型元素

转载 作者:数据小太阳 更新时间:2023-10-29 02:18:35 25 4
gpt4 key购买 nike

我有以下 XML:

<Envelope>
<Body>
<RESULT>
<SUCCESS>TRUE</SUCCESS>
<RecipientId>9876543210</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."}

谁能告诉我我做错了什么?

最佳答案

Body 和 Result 也应该是一个类,因为它包含元素。有点像

[XmlRoot(ElementName = "Envelope")]
public class Add_Recipent_response
{
public Body Body { get; set; }
}

public class Body
{
public Result RESULT { get; set; }
}

public class Result
{
public string SUCCESS { get; set; }
public string RecipientId { get; set; }
public string ORGANIZATION_ID { get; set; }
}

关于c# - 意外的节点类型元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25688396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com