表情符号字符无法编码为JSON [英] Emoji characters cannot be encoded to JSON

查看:1068
本文介绍了表情符号字符无法编码为JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITextView ,我调用 messageField messageField 中的数据发布到以JSON形式显示的服务器。当用户键入表情符号字符时,我无法将数据编码为JSON。我认为Emoji使用Unicode编码。

I have an UITextView which I call messageField. The data within that messageField is posted to server presented as JSON. When the user types an Emoji character, I cannot encode the data to JSON. I am thinking that Emoji uses Unicode encoding.

有没有办法将表情符号字符编码为JSON?并从JSON到表情符号显示在 UILabel

Is there a way to encode an Emoji character to JSON? And back from JSON to Emoji to display in an UILabel?

推荐答案

修改 - 2016-03-03 请注意,此答案是在2011年撰写的,可能已不再相关。

Emoji字符只是用于呈现特定Unicode代码点的特定字体。 iOS使用一个Unicode私人使用区域来表示表情符号特定的代码点。将这些字符视为表情符号的唯一方法是具有表情符号字体以及知道如何从默认文本字体(例如Helvetica)切换到表情符字体的机器。

Emoji characters are just a specific font used to render specific unicode code points. iOS uses one of the Unicode Private Use Areas for Emoji-specific code points. The only way to view these "characters" as Emoji is to have an Emoji font available as well as a machine that knows how to switch from the default text font (such as Helvetica) to the emoji font.

我不知道你是如何编码你的JSON,但由于表情符号只是文本,不应该有任何问题,只要你传输的文本以Unicode格式,如UTF- 8或UTF-16。您不会在服务器端或数据库中看到它(除非您使用先前的先决条件查看数据),但您应该能够发送相同的原始字节,并且应该看起来相同。

I don't know how you're encoding your JSON but since Emoji are just text there shouldn't be any problems as long as you transport the text in a Unicode-friendly format such as UTF-8 or UTF-16. You won't see it on the server-side or in the database (unless you view the data with the previous prerequisites) but you should be able to send the same raw bytes back and it should look the same.

以下是一些可能会有帮助的帖子:

Here's some posts that might help a little more:

  • The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
  • Questions about iPhone emoji and web pages
  • iPhone Emoji

这篇关于表情符号字符无法编码为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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