Emoji characters cannot be encoded to JSON

后端 未结 6 1844
长发绾君心
长发绾君心 2021-01-31 06:29

I have a UITextView which I call messageField. The data within that messageField is POST-ed to server in JSON format. When th

6条回答
  •  长发绾君心
    2021-01-31 06:56

    Edit - 2016-03-03 Please note, this answer was written in 2011 and may no longer be relevant any more.

    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.

    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

提交回复
热议问题