我正在尝试加载包含德语字符的 rss (ö, ä, ü...)
xhrRequest.responseText 已包含转换后的字符 (\u00f ...)
无需手动替换,是否可以强制正确编码以使原始字符保持可见?
var url = 'https://apolut.net/feed/podcast/'
xhrRequest = new XMLHttpRequest();
xhrRequest.onreadystatechange = function() {
if (xhrRequest.readyState == 4) {
}
}
xhrRequest.onerror = function(e) {
};
xhrRequest.open('GET', url);
xhrRequest.setRequestHeader("Content-Type", "text/xml");
xhrRequest.send();
我的页面顶部确实有 utf:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
收到数据后,使用
decodeURIComponent()
再次将Unicode转为带有该字符的文本。
xhrRequest.onreadystatechange = function() {
if (xhrRequest.readyState == 4) {
if (xhrRequest.status == 200) {
var decodedResponse = decodeURIComponent(JSON.parse('"' + xhrRequest.responseText + '"'));
// Now decodedResponse contains the original characters
console.log(decodedResponse);
}
}
}