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 に答える