IOS无法正确解码json格式的表情符号unicode,表情符号图标显示为正方形 [英] IOS cannot decode emoji unicode in json format correctly, and Emoji icons are displayed as squares

查看:657
本文介绍了IOS无法正确解码json格式的表情符号unicode,表情符号图标显示为正方形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款iPhone应用程序,允许人们使用表情符号图标发送消息。我使用charset utf8mb4和collat​​ion utf8mb4_unicode_ci在Mysql中保存了图标,所有表情符号图标都正确保存在我的数据库中。但是,当我将json返回给客户端(php json_encode)时,表情符号被编码为:'\ ud83d\\\�',并且iPhone将其显示为正方形。但是,如果我以XML格式返回,表情符号图标将不会像这样变成unicode:'\ ud83d\\\�',它只是图标。

I am working on an iPhone app which allows people to send messages with Emoji icons. I saved the icon in Mysql with charset utf8mb4 and collation utf8mb4_unicode_ci, and all the emoji icons is saved correctly in my database. However, when I return json back to the client (php json_encode), the Emoji is encoded as something like this: '\ud83d\ude04', and iPhone displays it as a square. However, if I return as XML, the Emoji Icon won't become unicode like this: '\ud83d\ude04', it will just be the icon.

我想知道这是在我的服务器上还是在我的客户端上的问题。如果它是我的客户端,对象c如何正确解码它。

I am wondering if this is an issue on my server, or on my client. If it is my client, how can object c decode it correctly.

有人可以帮忙吗?

谢谢

推荐答案

\\\�\\\� U + D83D U +的JSON Unicode转义序列DE04 ,这是 代理对 为Unicode的U + 1F604(微笑的OPEN嘴和微笑的眼睛FACE)。

"\ud83d\ude04" is the JSON Unicode escape sequence for U+D83D U+DE04, which is the "surrogate pair" for the Unicode U+1F604 (SMILING FACE WITH OPEN MOUTH AND SMILING EYES).

但是 NSJSONSerialization 正确解码,如以下示例所示:

But NSJSONSerialization decodes this correctly, as can be seen in the following example:

const char *jsonString = "{ \"emoji\": \"\\ud83d\\ude04\" }";
NSLog(@"JSON: %s", jsonString);
NSData *jsonData = [NSData dataWithBytes:jsonString length:strlen(jsonString)];
NSError *error;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.myLabel.text = [jsonDict objectForKey:@"emoji"];
NSLog(@"Emoji: %@", self.myLabel.text);

输出:

这篇关于IOS无法正确解码json格式的表情符号unicode,表情符号图标显示为正方形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆