iOS从URL字符串中删除特殊字符

时间:2012-08-15 08:13:46

标签: ios urlencode nsurlrequest

我想使用NSURLRequest调用此URL:

http://www.test.com/query= { “TAG1”: “üğişi”, “TAG2”: “çöçödd”}

这些字符是“üğişi”和“çöçödd”UTF8字符。我需要转换此URL以获得响应。你能救我吗?

1 个答案:

答案 0 :(得分:4)

使用-(NSString*)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding;课程的NSString例程。像这样:

NSString* url = @"http://www.test.com/query={\"tag1\":\"üğişi\",\"tag2\":\"çöçödd\"}"; 
NSString* urlEncoded = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Here you can find more...