Sencha Touch, OpenLayers, GeoServer: Wrong encoding on devices using Android 2.2

血红的双手。 提交于 2019-12-06 04:36:40

I have faced exactly the same problem using GeoServer, openLayers, and Android browser (Android 2.2).

I made some research looking for place where the problem exist. All in all I went down to XMLHttpRequest.js. In this file openLayers is creating XMLHttpRequest object making request and receiving response. I have found also that in this stage already received data has encoding problem.

I have also sniffed communication using wireshark to assure that data I am sending is in correct encoding (utf-8). I dumped this data and figured out that it was correct utf-8 data. But what was interesting that when I tried display my utf-8 data using iso-8859-1 I received exactly the same output as in Android browser.

My conclusion: In android 2.2 web browser XMLHttpRequest object is always reading data assuming iso-8859-1 encoding.

My solution: You have to fix string yourself. First you have to made map where you have to memorize that for instance "ø" is "ø". And then by examining character by character when you find "ø" sequence substitute it by "ø". This is example code:

goodString = "";
for( i = 0; i < wrongString.length; i++) {
    var w = wrongString.charCodeAt(i);
    var c = wrongString.charAt(i);
    if(w == "Ã".charCodeAt(0) {
        w2 = wrongString.charCodeAt(++i);
        if(w2 == "¸".charCodeAt(0))
            c = 'ø';
    }
    goodString += c;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!