获取数据的url:http://blog.home.blogbus.com/api/5600957/comments/107814818/comments
其中的一段数据"commentText":"\u5b9e\u4f53\u5e97\u91cc\u5c31\u5168\u662f\u767d\u83dc\u4e86\uff01\uff01"
\u5b9e\u4f53\u5e97\u91cc\u5c31\u5168\u662f\u767d\u83dc\u4e86\uff01\uff01
上面这串字符串是什么编码格式的?如何用.net的函数对它进行解码呢??
public static string Decode(string strDecode)
{
string sResult = "";
for (int i = 0; i < strDecode.Length / 4; i++)
{ sResult += (char)short.Parse(strDecode.Substring(i * 4, 4), global::System.Globalization.NumberStyles.HexNumber);
}
return sResult;
}
试试用javascript解码看看,decodeURIComponent函数,.net用 System.Web.HttpUtility.UrlDecode试试
Console.WriteLine("\u5b9e\u4f53\u5e97\u91cc\u5c31\u5168\u662f\u767d\u83dc\u4e86\uff01\uff01");
直接就可以输出自动解码
你好,这是Unicode编码格式。
private static void Decoding()
{
string source = "\u5b9e\u4f53\u5e97\u91cc\u5c31\u5168\u662f\u767d\u83dc\u4e86\uff01\uff01";
Console.WriteLine("Source:{0}",source);
string mirror = "实体店里就全是白菜了!!";
Console.WriteLine("Mirror:{0}",mirror);
Console.WriteLine("Source == Mirror : {0}",source.Equals(mirror));
//编码
byte[] bt = Encoding.Unicode.GetBytes(mirror);
Stream stream = new MemoryStream(bt);
BinaryReader reader = new BinaryReader(stream);
while (reader.BaseStream.Position < stream.Length)
{
Console.Write(@"\u{0}", reader.ReadInt16().ToString("x4"));
}
}