关于ComponentArt的中文乱码终极解决办法。
打开ComponentArt的源码,
ComponentArt的接受字符是按照Encode.Default来编码的,就是说采用的系统默认编码。我们可以改成UTF-8
例如:
protected void LoadClientData(string sData)
{
string tempData=sData;//缓存接受字符
try
{
if (sData != string.Empty)
{
this.nodes.Clear();
sData = HttpUtility.UrlDecode(sData, Encoding.Default);
// make it xml-safe
sData = sData.Replace("&", "#$cAmp@*");
XmlDocument oXmlDoc = new XmlDocument();
try{
oXmlDoc.LoadXml(sData);
}
catch{
sData = HttpUtility.UrlDecode(HttpUtility.UrlDecode(tempData, Encoding.UTF8));
oXmlDoc.LoadXml(sData); //不改动原来代码,在CATCH里面重新取值为UTF8编码
}
XmlNode oRootNode = oXmlDoc.DocumentElement;
if (oRootNode != null && oRootNode.ChildNodes.Count > 0)
{
this.LoadClientXmlNodes(oRootNode.ChildNodes, -1, this.nodes);
// fix up pointers
this.ComponentArtFixStructure();
}
}
}
catch (Exception ex)
{
throw new Exception("Error loading client data: " + ex);
}
}
以上代码来自
BaseNavigator.cs 行1400左右。
出处:http://slave2.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。