2 に答える
I hope this will help you...I'm using this and e106 is my emoji code.
Only replcare with content line with below line:
content = [NSString stringWithFormat:@"%C", 0xe106];
U+F44D
is 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+1F44D
is the "THUMBS UP SIGN", so it could be that your Web service does not create a correct JSON response for Unicode characters greater than 0xFFFF
.
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+1F44D
character the JSON Unicode escape sequence would be "\ud83d\udc4d".
The following code shows that it works in general:
const char *s = "{ \"content\": \"\\ud83d\\udc4d\", \"id\": 104, \"time\": 1350359055 }";
NSData *jsonData = [NSData dataWithBytes:s length:strlen(s)];
NSError *error;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.label.text = [jsonDict objectForKey:@"content"];
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.