小编Ogn*_*nić的帖子

使用Android + GAE 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)

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

google-app-engine android character-encoding google-cloud-endpoints

6
推荐指数
1
解决办法
1177
查看次数

Python在Java中编码了utf-8 string\xc4\x91

如何从Python创建正确的Java字符串创建字符串'Oslobo\xc4\x91enja'?怎么解码呢?我已经尝试过,我认为一切,到处都是,我已经被这个问题困住了2天.请帮忙!

这是Python的Web服务方法,它返回JSON,Google Gson的Java客户端从中解析它.

def list_of_suggestions(entry):
   input = entry.encode('utf-8')
   """Returns list of suggestions from auto-complete search"""
   json_result = { 'suggestions': [] }
   resp = urllib2.urlopen('https://maps.googleapis.com/maps/api/place/autocomplete/json?input=' + urllib2.quote(input) + '&location=45.268605,19.852924&radius=3000&components=country:rs&sensor=false&key=blahblahblahblah')
   # make json object from response
   json_resp = json.loads(resp.read())

   if json_resp['status'] == u'OK':
     for pred in json_resp['predictions']:
        if pred['description'].find('Novi Sad') != -1 or pred['description'].find(u'???? ???') != -1:
           obj = {}
           obj['name'] = pred['description'].encode('utf-8').encode('string-escape')
           obj['reference'] = pred['reference'].encode('utf-8').encode('string-escape')
           json_result['suggestions'].append(obj)

   return str(json_result)
Run Code Online (Sandbox Code Playgroud)

这是Java客户端的解决方案

private String python2JavaStr(String pythonStr) throws UnsupportedEncodingException {
    int charValue;
    byte[] bytes = …
Run Code Online (Sandbox Code Playgroud)

python java string utf-8 utf8-decode

6
推荐指数
1
解决办法
2448
查看次数