C#: 中文和UNICODE字符转换方法 及仿安居客地图实现。。。错误 GMap2未定义 解决办法 -VB 中文转为UNICODE字符
Posted on 2010-04-09 11:31 且行且思 阅读(1254) 评论(0) 编辑 收藏 举报错误 GMap2未定义 解决办法 (关键在于:charset="utf-8" )
<script src="http://maps.google.com/maps?file=api&v=2&sensor=false&key=ABQIAAAAnzgK6D9hdvlLyVMROdMgRxRvkvyC2uHS-ibWMJG7xp28q6sn4RSCVBqVh-Kb2lwBiDjnbXc4A9U_XQ" type="text/javascript" charset="utf-8"></script>
''/////************************* VB 中文转为UNICODE字符
''//中文转为UNICODE字符
''Dim str As String = "新景花园"
''Dim outStr As String = ""
''Dim i As Integer = 0
''For i = 1 To str.Length
'' outStr = outStr + "\u" + Hex(AscW(Mid(str, i, 1))).ToString()
''Next i
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
context.Response.ContentType = "application/json";
context.Response.Charset = "utf-8";
string txt = "{\"50697\":[\"\u65b0\u666f\u5bb6\u56ed\",392,39.8957115,116.4256382]}";
context.Response.Write(txt);
//Response.Write("\u65b0\u666f\u5bb6\u56ed" + "<br>");
//Response.Charset = "utf-8";
//string str = "动网新闻";
//string outStr = "";
//if (!string.IsNullOrEmpty(str))
//{
// for (int i = 0; i < str.Length; i++)
// {
// //将中文字符转为10进制整数,然后转为16进制unicode字符
// outStr += "\\u" + ((int)str[i]).ToString("x");
// }
//}
//Response.Write(outStr);
//Response.End();
//////中文转为UNICODE字符
////string str = "中文";
////string outStr = "";
////if (!string.IsNullOrEmpty(str))
////{
//// for (int i = 0; i < str.Length; i++)
//// {
//// //将中文字符转为10进制整数,然后转为16进制unicode字符
//// outStr += "\\u" + ((int)str[i]).ToString("x");
//// }
////}
//////UNICODE字符转为中文
////string str = "\\u4e2d\\u6587";
////string outStr = "";
////if (!string.IsNullOrEmpty(str))
////{
//// string[] strlist = str.Replace("\\", "").Split('u');
//// try
//// {
//// for (int i = 1; i < strlist.Length; i++)
//// {
//// //将unicode字符转为10进制整数,然后转为char中文字符
//// outStr += (char)int.Parse(strlist[i], System.Globalization.NumberStyles.HexNumber);
//// }
//// }
//// catch (FormatException ex)
//// {
//// outStr = ex.Message;
//// }
////}
context.Response.Charset = "utf-8";
string txt = "{\"50697\":[\"\u65b0\u666f\u5bb6\u56ed\",392,39.8957115,116.4256382]}";
context.Response.Write(txt);
//Response.Write("\u65b0\u666f\u5bb6\u56ed" + "<br>");
//Response.Charset = "utf-8";
//string str = "动网新闻";
//string outStr = "";
//if (!string.IsNullOrEmpty(str))
//{
// for (int i = 0; i < str.Length; i++)
// {
// //将中文字符转为10进制整数,然后转为16进制unicode字符
// outStr += "\\u" + ((int)str[i]).ToString("x");
// }
//}
//Response.Write(outStr);
//Response.End();
//////中文转为UNICODE字符
////string str = "中文";
////string outStr = "";
////if (!string.IsNullOrEmpty(str))
////{
//// for (int i = 0; i < str.Length; i++)
//// {
//// //将中文字符转为10进制整数,然后转为16进制unicode字符
//// outStr += "\\u" + ((int)str[i]).ToString("x");
//// }
////}
//////UNICODE字符转为中文
////string str = "\\u4e2d\\u6587";
////string outStr = "";
////if (!string.IsNullOrEmpty(str))
////{
//// string[] strlist = str.Replace("\\", "").Split('u');
//// try
//// {
//// for (int i = 1; i < strlist.Length; i++)
//// {
//// //将unicode字符转为10进制整数,然后转为char中文字符
//// outStr += (char)int.Parse(strlist[i], System.Globalization.NumberStyles.HexNumber);
//// }
//// }
//// catch (FormatException ex)
//// {
//// outStr = ex.Message;
//// }
////}
仿安居客地图