Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java和python中的Unicode字符串支持_Java_Android_Python_Google App Engine_Unicode - Fatal编程技术网

java和python中的Unicode字符串支持

java和python中的Unicode字符串支持,java,android,python,google-app-engine,unicode,Java,Android,Python,Google App Engine,Unicode,我有一个Android应用程序,我在其中阅读短信并将其发送到谷歌应用程序引擎服务器。一些用户抱怨某些语言不能正常使用 // Execute query cursor = context.getContentResolver().query( SMS_PROVIDER_URI, SMS_QUERY_FIELDS, "date >= " + startDate.get

我有一个Android应用程序,我在其中阅读短信并将其发送到谷歌应用程序引擎服务器。一些用户抱怨某些语言不能正常使用

        // Execute query
        cursor = context.getContentResolver().query(
                SMS_PROVIDER_URI,
                SMS_QUERY_FIELDS,
                "date >= " + startDate.getTime(),  // selection - get messages > startDate
                null,                              // selectionArgs
                "date ASC");                       // order - get oldest messages first

        // Iterate results
        if (cursor != null && cursor.moveToFirst()) {

            // read through all the sms and create a list
            do {
                String sender              = cursor.getString(0);
                String message             = cursor.getString(2);
                boolean isIncomingMessage  = cursor.getString(3).contains("1");
                Date date                  = new Date(cursor.getLong(1));

                String contactName = ContactLookup.lookup(context, sender);

                smsList.add(new SMSMessageInfo(sender, contactName,
                        message, isIncomingMessage, date));

            } while (cursor.moveToNext());
        }
message变量包含来自不同语言的sms消息。我如何支持它?
此外,我需要将其发送到我的服务器(python)以及如何在服务器上翻译unicode?

在python 2.7中,有两类字符串,
str
(标准字符串,由字节组成)和
unicode
(由unicode字符组成,使用u前缀表示为文字:u“foo”)。转换通过使用实例上的方法完成:

u"blä".encode('utf8') → "bl\xc3\xa4"  # from unicode to str
"bl\xc3\xa4".decode('utf8') → u"blä"  # from str to unicode
转换通常是隐式进行的,例如。G如果将
str
添加到
unicode
,则在连接之前,
str
将升级为
unicode
(默认情况下使用编码
ascii

另一方面,获得
print
ed的
unicode
实例将首先转换为
str
,使用一种取决于打印流的编码(通常也是
ascii


这些自动转换的情况通常是异常的来源(即如果转换失败)。如果捕捉到太多异常,这些异常可能会被忽略,然后某些功能就无法工作。

Python与Unicode配合使用效果很好。以下是一篇综合文章: