iOS Unicode 上传表情和显示表情

1、上传表情到后台 Unicode编码

     NSString *uniStr = [NSString stringWithUTF8String:[comments UTF8String]];

    NSData *uniData = [uniStr dataUsingEncoding:NSNonLossyASCIIStringEncoding];

    NSString *goodStr = [[NSString alloc] initWithData:uniData encoding:NSUTF8StringEncoding] ;

2、显示后台返回的表情 Unicode 解码

     NSString *str = comments;

    constchar *jsonString = [str UTF8String];  // Emoji表情编解码

    NSData *jsonData = [NSData dataWithBytes:jsonString length:strlen(jsonString)];

    NSString *goodMsg1 = [[NSString alloc] initWithData:jsonData  encoding:NSNonLossyASCIIStringEncoding];

注:comments 上传字符串

你可能感兴趣的:(iOS Unicode 上传表情和显示表情)