之前做弹幕的时候 遇到的表情编码解码问题
表情编码一般是使用unicode编码 ,编码之后的格式 \ud83d\ude18\ud83d\ude18world\u4e16\u754chaha\ud83d\ude17
//编码 NSString *uniStr = [NSString stringWithUTF8String:[_barrageText.text UTF8String]]; NSData *uniData = [uniStr dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *goodStr = [[NSString alloc] initWithData:uniData encoding:NSUTF8StringEncoding] ; NSLog(@"---编码--->[%@]",goodStr); //解码 const char *jsonString = [goodStr UTF8String]; // goodStr 服务器返回的 json NSData *jsonData = [NSData dataWithBytes:jsonString length:strlen(jsonString)]; NSString *goodMsg1 = [[NSString alloc] initWithData:jsonData encoding:NSNonLossyASCIIStringEncoding]; NSLog(@"---解码--->[%@]",goodMsg1); 2016-04-15 10:16:17.858 DFRomwe[650:153981] ---编码--->[hello\ud83d\ude18\ud83d\ude18world\u4e16\u754chaha\ud83d\ude17] 2016-04-15 10:16:17.859 DFRomwe[650:153981] ---解码--->[hello????world世界haha??]
时间: 2024-10-09 04:57:52