我试图通过 SO 进行搜索,但找不到解决方案。
我的 iOS 接收来自用户的评论 (NSString) 并通过 Http POST 将其发送回服务器,然后如果用户想再次查看该评论,评论将通过 Http get 发回。我在 UILabel 中显示它。
如果评论包含表情符号(笑脸等),我似乎无法正确显示评论
当我输入表情符号时。控制台显示在发布到服务器之前的数据是“\Ud83d\Ude1d” 当我通过 JSON 从我的服务器取回它时,它就是这个字符串 "\Uf61d"。它只显示在方框字母中,而不是正确的表情符号。
这是我发送到服务器时的代码(NSUTF8Encoding)
NSDictionary *postDetailDict = [NSDictionary
dictionaryWithObjectsAndKeys:
itemID,@"item_id",
title,@"title",
nil];
for (NSString *param in postDetailDict) {
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", param] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"%@\r\n", [postDetailDict objectForKey:param]] dataUsingEncoding:NSUTF8StringEncoding]];
}
当我收到从 HTTP GET 返回的数据时。我只是用
[commentObject setComment:[d objectForKey:@"comment"]];
[commentLabel setLabel:commentObject.comment];
有人请帮忙。我的服务器在 Heroku (Rails) 上
提前致谢
最佳答案
我找到了解决方案。它与前端无关。这是关于从我的 Rails 服务器返回的 JSON 未正确解码的方式。 此解决方法可以为遇到相同问题的人解决此问题
关于ios - 当我的 iOS 应用程序将数据发送到服务器(POST,GET)时如何处理表情符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25712467/