1

我正在使用以下代码片段实现搜索。

-(void)getData:(NSString *)searchString
{
    //Search string is the string the user keys in as keywords for the search. In this case I am testing with the keywords "epic headline"
    searchString = [searchString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *resourcePath = [NSString stringWithFormat:@"/sm/search?limit=100&term=%@&types[]=users&types[]=questions&types[]=topics",searchString];

    [self sendRequests:resourcePath];
}


//URL sent to server as a result
send Request /sm/search?limit=100&term=epic headline&types[]=users&types[]=questions&types[]=topics

我的搜索不起作用,因为它无法处理“史诗”和“标题”之间的空格。如何修改搜索词以便处理间距?

4

1 回答 1

3

对结果字符串调用 stringByAddingPercentEscapesUsingEncoding 以按照 URL 规则的要求对空格字符进行编码。

于 2012-05-05T02:56:49.213 回答