【问题标题】:Messed up character encoding with Android + GAE Cloud Endpoints使用 Android + GAE Cloud Endpoints 搞乱字符编码
【发布时间】:2013-06-18 11:15:01
【问题描述】:

我使用 GAE 的 Cloud Endpoints 制作了 Web 应用程序。应用程序只有后端部分。 应用程序调用 Google Places API 并解析 JSON 响应,创建返回给客户端的对象。客户端是使用 GAE 生成的客户端库的 Android 应用。

我的问题如下:在本地开发服务器上运行的应用程序在 Android 上正确显示了 UTF-8 格式的字符串,但已部署的应用程序在 Android 上显示的字符串混乱。 例如:而不是 Klinički Centar,它显示 Klini��ki Centar。

我正在使用最新的 Fedeora GNU/Linux,在 Eclipse Kepler(最新版本)中开发,GAE 版本为 1.8.1,Google Plugin for Eclipse 版本 3.2.4(最新版本)。

为了解决这个问题,我已经浪费了大量的时间。 我认为解决方案是一些强制 UTF-8 的配置行。 顺便提一下,我的appengine-web.xml 有以下内容:

<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>

提前感谢您的每一个建议。

【问题讨论】:

    标签: android google-app-engine character-encoding google-cloud-endpoints


    【解决方案1】:

    解决了!!!!

    我认为这是谷歌的错误,就像我的一样。 我假设响应将以 UTF-8 编码,所以我只使用了:

    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()));
    

    通过显式添加 charset 参数,一切顺利:

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

    但 Google 肯定需要了解为什么它在本地和部署中的行为不同。

    祝大家万事如意,感谢大家的关注和努力!

    【讨论】:

      猜你喜欢
      • 2011-03-13
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 2013-06-03
      • 2016-04-29
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      相关资源
      最近更新 更多