带有特殊字符的NSURL(åäö)

编程入门 行业动态 更新时间:2024-10-27 08:26:56
本文介绍了带有特殊字符的NSURL(åäö)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的服务器上有一些用特殊字符(å,ä,ö)命名的图像.我不知道如何转换NSUrl来获取它们:

I have some images on my server, named with special characters (å,ä,ö). I can't figure out how to convert the NSUrl to get them:

NSString *urlString = [NSString stringWithFormat: @".../Images/%@Image.png", playerName]; NSURL *url = [NSURL URLWithString: [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSLog(@"url:%@", url); //Get the image and assign it to the player NSData *imageData = [NSData dataWithContentsOfURL:url]; UIImage *image = [UIImage imageWithData:imageData];

上面示例中的日志(如果"playerName" =åäö):

The log in the above example (if "playerName" = åäö):

.../Images/%C3%A5%C3%A4%C3%B6Image.png

但我需要这样:

.../Images/åäöImage.png

我尝试了不同的(stringByAddingPercentEscapesUsingEncoding)和下面的代码,但未成功:

I tried different (stringByAddingPercentEscapesUsingEncoding) and the code below without success:

- (NSString *)URLEncodingOfString:(NSString *)s { return (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes (kCFAllocatorDefault, (__bridge CFStringRef)s, NULL, NULL, kCFStringEncodingISOLatin1); }

任何建议都非常感谢, 预先感谢

Any advice is very appreciated, Thanks in advance

推荐答案

我认为这完全取决于Web服务器使用的编码方式.

I think it'll depend entirely on what encoding the web server is using.

由于从您的测试看来ISO-Latin-1似乎无法正常工作,因此您可以尝试将kCFStringEncodingISOLatin1替换为kCFStringEncodingUTF8.

Since ISO-Latin-1 doesn't seem, from your test, to work, you might try replacing kCFStringEncodingISOLatin1 with kCFStringEncodingUTF8.

更多推荐

带有特殊字符的NSURL(åäö)

本文发布于:2023-11-16 11:55:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1604059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:特殊字符   NSURL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!