【发布时间】:2019-03-02 13:07:27
【问题描述】:
我有一个需要反序列化的字符串,它是一个响应
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">
<soap:Body>
<TestResponse xmlns=\"http://tempuri.org/\">
<TestResult>
<code>1</code>
<msg>Message was successfully sent</msg>
<sent />
</TestResult>
</TestResponse>
</soap:Body>
</soap:Envelope>
这是我的反序列化代码
string s = System.Text.ASCIIEncoding.ASCII.GetString(result);
Test_Response resp = new Test_Response();
using (var stringReader = new System.IO.StringReader(s))
{
var serializer = new XmlSerializer(typeof(Test_Response));
resp = (Test_Response)serializer.Deserialize(stringReader);
}
return s;
这是我的课
[Serializable(), XmlRoot("TestResult")]
public class Test_Response
{
public string code { get; set; }
public string msg { get; set; }
public string sent { get; set; }
}
那么错误信息就是
XML 文档中存在错误 (1, 40)。
内部异常是
<Envelope xmlns='http://www.w3.org/2003/05/soap-envelope'> was not expected.
谁能帮帮我。谢谢
【问题讨论】:
标签: c# xml xml-deserialization