I am making an app that posts content from a UITextField, to a PHP script, and store in a database to read later. I am having one heck of a time working with emojis.
Using json, I will get a response like this:
content = "\Uf44d";
id = 104;
time = 1350359055;
In this instance, I used an emoji. But when I do [dictionary objectForKey:@"content"], a box just appears.
I’m thinking I need to convert to UTF-8. But I’m not completely sure. Please help!
U+F44Dis a Unicode character in the “Private Use Area”U+E000..U+F8FF, so that is probably not the character you want to display.On the other hand,
U+1F44Dis the “THUMBS UP SIGN”, so it could be that your Web service does not create a correct JSON response for Unicode characters greater than0xFFFF.According to the JSON RFC, characters that are not part of the “Basic Multilingual Plane” can be escaped using a UTF-16 surrogate pair. For the
U+1F44Dcharacter the JSON Unicode escape sequence would be “\ud83d\udc4d”.The following code shows that it works in general:
This displays the “THUMBS UP SIGN” correctly in the label.
But you don’t have to escape characters, the Web service could also just send the UTF-8 sequence.