日期:2014-05-17 浏览次数:20865 次
public T Parse<T>(string body) where T : DdResponse { XmlSerializer serializer; var xml = new XmlDocument(); xml.LoadXml(body); if (xml.DocumentElement != null) { var innerXml = xml.DocumentElement.InnerXml; xml.RemoveChild(xml.DocumentElement); var xmlElement = xml.CreateElement(typeof(T).Name); xmlElement.InnerXml = innerXml; xml.AppendChild(xmlElement); body = xml.InnerXml; } var rootTagName = typeof(T).Name; var inc = Parsers.TryGetValue(rootTagName, out serializer); if (!inc || serializer == null) { var rootAttrs = new XmlAttributes { XmlRoot = new XmlRootAttribute(rootTagName) }; var attrOvrs = new XmlAttributeOverrides(); attrOvrs.Add(typeof(T), rootAttrs); serializer = new XmlSerializer(typeof(T), attrOvrs); Parsers[rootTagName] = serializer; } object obj; //鼠标放在stream 上面的时候 提示2个异常 [color=#FF0000] stream.ReadTimeOut 引发了“System.InvalidOperationexception”类型的异常 stream.ReadTimeOut 引发了“System.InvalidOperationexception”类型的异常 [/color] using (Stream stream = new MemoryStream(_encoding.GetBytes(body.Trim()))) { [color=#FF0000] obj = serializer.Deserialize(stream);[/color] //obj这句话 报错:就走不下去了, stream.ReadTimeOut 引发了“System.InvalidOperationexception”类型的异常 stream.ReadTimeOut 引发了“System.InvalidOperationexception”类型的异常 未处理 InvaidOpertionException XML 文档(0, 0)中有错误。 ---都说是XML问题!XML 打开的没啥问题呀!可能是流转换的时候问题! stream.Close(); }