【问题标题】:Objective C - NSURL - Quotation markObjective C - NSURL - 引号
【发布时间】:2012-05-26 20:31:17
【问题描述】:

我已经在网站上搜索了没有结果的答案,所以我在这里提出一个问题。

我正在使用 CouchDB,我将使用视图,但问题是当我为 NSURLConnection 创建 URL 时,我不能在 NSURL 中使用引号 (")。

这是我的代码:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://127.0.0.1:5984/users/_design/search/_view/phone?key=\"0701010100\""]];

如果我不使用这些引号,CouchDB 认为这是一个数字。

感谢大家的帮助。

马库斯

【问题讨论】:

    标签: objective-c nsstring nsurlconnection nsurl quotation-marks


    【解决方案1】:

    使用-stringByAddingPercentEscapesUsingEncoding:

    NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"http://127.0.0.1:5984/users/_design/search/_view/phone?key=\"0701010100\""] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    

    【讨论】:

    • 感谢您的回答!我通过在键值之前和之后输入 %%22 来做到这一点。但我想我会改用你的代码。 ;)
    猜你喜欢
    • 2012-11-04
    • 2015-12-06
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-24
    • 2011-06-26
    • 2014-10-14
    • 2014-10-25
    相关资源
    最近更新 更多