西班牙语字符编码 - iphone

发布于 2024-10-25 20:07:35 字数 202 浏览 1 评论 0原文

我正在将文本从 iphone 发送到服务器进行处理。 文本包含一些西班牙语字符,例如 á é í ó ú ü ñ ¿ ¡ ºª

发送时,我使用 NSUTF8StringEncoding 对其进行编码 服务器端也是使用UTF8编码来解码。

但服务器端将其解码为??????

请告诉我是否有人遇到过这个问题以及如何解决的?

谢谢。

I am sending text from iphone to the server for processing.
The text contain some spanish characters eg, á é í ó ú ü ñ ¿ ¡ ºª

While sending, I am encoding it with NSUTF8StringEncoding
Server side is also using UTF8 encoding to decode it.

But the server side decodes it as ???????

Please let me know if anyone has faced this issue and how this was resolved ?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

送舟行 2024-11-01 20:07:35

我找到了解决方案。

由于这是一个帖子数据,我必须转义特殊字符。

stringByAddingPercentEscapesUsingEncoding: 似乎没有转义所有特殊字符。我遇到了“+”字符的问题,它被空格替换了。

我觉得西班牙字符也会发生同样的情况,它没有正确转义,所以我手动替换了它并且它起作用了。

下面是一个例子。我为所有角色写了这篇文章,

escapedString = [escapedString stringByReplacingOccurrencesOfString:@"À" withString:@"%C0"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Á" withString:@"%C1"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Â" withString:@"%C2"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Ã" withString:@"%C3"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Ä" withString:@"%C4"];

谢谢 xj1200 和 saadnib 的关注。我真的很感激。如果你们发现任何其他更好的解决方案,请发布。

I found the solution.

Since this is a post data I had to escape the special characters.

stringByAddingPercentEscapesUsingEncoding: doesn't seem to escape all the special characters. I faced this issue with "+" character where it was getting replaced by a whitespace.

I feel same thing happens with spanish character where it is not escaped properly, so I manually replaced it and it worked.

following is an example. I wrote this for all the characters

escapedString = [escapedString stringByReplacingOccurrencesOfString:@"À" withString:@"%C0"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Á" withString:@"%C1"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Â" withString:@"%C2"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Ã" withString:@"%C3"];        
        escapedString = [escapedString stringByReplacingOccurrencesOfString:@"Ä" withString:@"%C4"];

Thank you xj1200 and saadnib for looking in to this. I really appreciate. If you guys find any other better solution please post.

撕心裂肺的伤痛 2024-11-01 20:07:35

我认为您可以使用 Google Toolbox for Mac 对这些字符进行编码。查看文件 GTMNSString+

http ://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/?r=27#trunk%2FFoundation

I think you can use Google Toolbox for Mac for ancoding these characters. See files GTMNSString+

http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/?r=27#trunk%2FFoundation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文