我有這樣的XML:DataContract反序列化XML
<ResultData xmlns="http://schemas.datacontract.org/2004/07/TsmApi.Logic.BusinesEntities"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Information>Schedule added.</Information>
<Success>true</Success>
</ResultData>
有沒有辦法讓作爲結果只有:
<ResultData>
<Information>Sched added.</Information>
<Success>true</Success>
</ResultData>
沒有從下面的示例中,所有其他的事情? 因爲當我嘗試獲取下面顯示的結果字符串的對象時,它不起作用。
Datacontract XML serialization
我嘗試使用的代碼是:
var serializer = new XmlSerializer(typeof(ResultData));
var rdr = new StringReader(xmlResultString);
var resultingMessage = (ResultData)serializer.Deserialize(rdr);
並在最後一排它爲我的錯誤:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Xml.dll
Additional information: There is an error in XML document (1, 2).
<ResultData xmlns='http://schemas.datacontract.org/2004/07/TsmApi.Logic.BusinesEntities'> was not expected.
ResultData:
[DataContract]
public class ResultData
{
[DataMember]
public bool Success
{
get;
set;
}
[DataMember]
public string Information
{
get;
set;
}
}
顯示你的代碼並定義「不起作用」,否則你很可能無法得到幫助是零。我們不是clairvoyants .... – Tim 2014-11-01 09:15:12
我編輯了我的問題。謝謝。 – dillci 2014-11-01 14:56:47
@dillci Again ... ResultData類在哪裏? – Aron 2014-11-01 15:42:18