Spanish character encoding - iphone

2019-06-13 16:17发布

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.

2条回答
Melony?
2楼-- · 2019-06-13 17:01

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.

查看更多
唯我独甜
3楼-- · 2019-06-13 17:02

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

查看更多
登录 后发表回答