与Android + GAE云端点搞砸字符编码云端、字符、Android、GAE

2023-09-04 09:55:50 作者:本地区己覆盖4妓网络

我使用GAE的云端点做出的Web应用程序。应用程序只有后端的一部分。 应用程序调用谷歌的地方API和解析JSON响应,创建返回到客户端对象。客户端是Android应用程序,它使用生成的客户端库从GAE。

I made web app using GAE's Cloud Endpoints. App has only backend part. App calls Google Places API and parses JSON responses, creating objects which returns to client. Client is Android app which uses generated client libraries from GAE.

我的问题是如下因素:本地开发服务器上运行的应用程序显示在Android正确的UTF-8格式的字符串,但部署的应用程序是显示在Android搞砸字符串。 例如:不是Klinički辛塔尔它表明Kliniki辛塔尔

My problem is folowing: app running on local dev server shows on Android correctly UTF-8 formatted strings, but deployed app is showing on Android messed up strings. E.g: Instead of Klinički Centar it shows Klini��ki Centar.

我使用的是最新的Fedeora的GNU / Linux,在Eclipse开普勒(最新版)的开发,GAE是版本1.8.1,谷歌Eclipse插件版本3.2.4(最新的)。

I'm using latest Fedeora GNU/Linux, developing in Eclipse Kepler (newest edition), GAE is ver 1.8.1, Google Plugin for Eclipse ver 3.2.4 (latest).

我已经失去了时间令人难以置信的大量努力解决这个问题。 我认为解决办法是一些配置线,迫使UTF-8。 只是提了​​,我在我的 AppEngine上-web.xml中如下因素:

I have lost incredible amount of time trying to solve this. I assume solution is some config line which forces UTF-8. Just to mention, I have in my appengine-web.xml folowing:

<system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties" />
    <property name="file.encoding" value="UTF-8" />
    <property name="DEFAULT_ENCODING" value="UTF-8" />
</system-properties>

先感谢您的每一个建议。

Thanks in advance for every suggestion.

推荐答案

我认为这是谷歌的错误均匀矿山。 我认为反应将是连接codeD的UTF-8,所以我只是用:

SOLVED IT!!!!

I think that this is Google's bug evenly as mine. I assumed that response will be encoded in UTF-8, so I just used:

URL url = new URL(PLACE_AC_API + encodedInput + PLACE_AC_API_OPTIONS);
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

通过明确添加字符集参数一切工作:

With explicitly adding charset argument everything worked out:

BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8")));

不过,谷歌一定要明白为什么这个行为不同的地方和部署。

But Google definitely need to see why this behaves differently in local and deployed.

所有最好的给大家,感谢有趣和努力!

All the best to everyone, thanks for interesting and effort!