【问题标题】:special character return nil in nsurlnsurl 中的特殊字符返回 nil
【发布时间】:2010-08-09 14:38:01
【问题描述】:

我有一个这样的 nsstring

http://example.com/webservices/test?method=eventlist&title=Prog%

我想将此 nsstring 更改为 nsurl,但它在 nsurl 中返回 nil。我知道它返回 nil 因为最后的百分比,但我想在每个标题中添加百分比以获得一个值。所以我不知道如何做到这一点?

谁能帮帮我?

提前致谢…………

【问题讨论】:

    标签: iphone


    【解决方案1】:

    您需要将特殊字符编码为 URL 代码:

    NSString *encodedURLString = [urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
    
    NSURL *URL = [NSURL URLWithString:encodedURLString];
    

    【讨论】:

    猜你喜欢
    • 2015-07-30
    • 2014-11-24
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    相关资源
    最近更新 更多