Ogn*_*nić 6 google-app-engine android character-encoding google-cloud-endpoints
我使用GAE的Cloud Endpoints创建了Web应用程序.应用程序只有后端部分.应用程序调用Google Places API并解析JSON响应,创建返回客户端的对象.客户端是Android应用程序,它使用GAE生成的客户端库.
我的问题如下:在本地开发服务器上运行的应用程序在Android上正确显示UTF-8格式的字符串,但部署的应用程序在Android上显示混乱的字符串.例如:而不是KliničkiCentar,它显示了Klini kiCentar.
我正在使用最新的Fedeora GNU/Linux,在Eclipse Kepler(最新版本)中开发,GAE是1.8.1版本,Google插件用于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>
Run Code Online (Sandbox Code Playgroud)
提前感谢您的每一个建议.
我认为这既是谷歌的错误,也是我的错误。我假设响应将以 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()));
Run Code Online (Sandbox Code Playgroud)
通过显式添加字符集参数,一切顺利:
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8")));
Run Code Online (Sandbox Code Playgroud)
但谷歌肯定需要了解为什么这在本地和部署中表现不同。
祝大家一切顺利,感谢您的兴趣和努力!
| 归档时间: |
|
| 查看次数: |
1177 次 |
| 最近记录: |