有时候我们通过发送请求JSON,发现返回来的中文是unicode(如\u888)那么我们想要得到中文怎么做呢?下面的方法可以实现转码
string GetFromUtf32(string strUtfCode)
{
string title = "";
string[] arOp = new string[] { "\\u" };
string[] arWord = strUtfCode.Split(arOp, StringSplitOptions.None);
foreach (string s in arWord)
{
if (s.Length == 0) continue;
if (s.Length == 4)
{
try
{
title += Char.ConvertFromUtf32(Convert.ToInt32(s, 16));
}
catch
{
title += s;
}
}
else if (s.Length < 4)
{
title += s;
}
else
{
try
{
title += Char.ConvertFromUtf32(Convert.ToInt32(s.Substring(0, 4), 16));
title += s.Substring(4);
}
catch
{
title += s;
}
}
}
return title;
}