当XML包含“Lord& Hogan”等数据时,以下代码会中断。有什么建议? 谢谢,肯
private T GetResponse<T>(String apiObject, String query)
{
//Deserialize XML into the type specified.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(BuildRequestUri(apiObject, query));
using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse())
{
try
{
XmlSerializer ser = new XmlSerializer(typeof(T));
return (T)ser.Deserialize(resp.GetResponseStream());
}
catch (Exception e)
{
error = e.InnerException.ToString();
return default(T);
}
}
}
答案 0 :(得分:3)
你应该对像“Lord&amp; Hogan”这样的数据进行XML编码。它应该编码如下:
"Lord & Hogan"
答案 1 :(得分:3)
&
应替换为&
,否则它将是无效字符。
答案 2 :(得分:3)
答案 3 :(得分:1)