我正在为瑞典公司构建Google Maps实施,因此该语言有很多用途ä,å和ö。我可以正确显示特殊字符(网站字符集是UTF-8),除了每个地图标记的“标题”属性。我的标记代码是(你可以忽略方括号中的所有内容):
var marker = new google.maps.Marker({
position: [coordinates],
map: [map container div],
icon: [icon image],
title: "Läs mer om "+[text from JSON] //THIS IS WHERE THE PROBLEM IS
});
当我将鼠标悬停在地图上的标记上时,工具提示会显示为“L�smerom om ...”。如果我在Javascript中将“ä”更改为ä
,则工具提示会显示“Läs mer om...
”。
踢球者是在网站的任何其他位置使用特殊字符,可以是直接在原始HTML中,也可以是由CMS放置的生成文本,或者您可以使用什么工作。它只是在谷歌地图实施中才开始破解。
同样,鉴于该网站完全采用瑞典语,这可能是一个相当重要的问题。来自SO居民天才的任何好主意?
我试一试,它在这里工作,
如果你需要如此快速地测试它,请尝试console.log("L\u00e4s mer om")
或alert("L\u00e4s mer om")
它会输出“Läsmerom”
资料来源:http://www.ietf.org/rfc/rfc4627.txt
2.5. Strings
The representation of strings is similar to conventions used in the C
family of programming languages. A string begins and ends with
quotation marks. All Unicode characters may be placed within the
quotation marks except for the characters that must be escaped:
quotation mark, reverse solidus, and the control characters (U+0000
through U+001F).
Any character may be escaped. If the character is in the Basic
Multilingual Plane (U+0000 through U+FFFF), then it may be
represented as a six-character sequence: a reverse solidus, followed
by the lowercase letter u, followed by four hexadecimal digits that
encode the character's code point. The hexadecimal letters A though
F can be upper or lowercase. So, for example, a string containing
only a single reverse solidus character may be represented as
"\u005C".
Alternatively, there are two-character sequence escape
representations of some popular characters. So, for example, a
string containing only a single reverse solidus character may be
represented more compactly as "\\".
To escape an extended character that is not in the Basic Multilingual
Plane, the character is represented as a twelve-character sequence,
encoding the UTF-16 surrogate pair. So, for example, a string
containing only the G clef character (U+1D11E) may be represented as
"\uD834\uDD1E".
解释:
因为标记是一个JS对象,所以它应该遵循上面列出的规则
{
position: [coordinates],
map: [map container div],
icon: [icon image],
title: "Läs mer om "+[text from JSON] //THIS IS WHERE THE PROBLEM IS
}
好吧那该怎么办???使用<?php echo json_encode("Läs mer om "); ?>
或任何服务器端语言
并将值附加到您的JSON对象或手动编写并继续!
我在ASP中确实喜欢这样:
作为代码:
replace(Server.URLEncode(objRS("case_description")),"+"," ")