我想使用NSURLRequest调用此URL:
http://www.test.com/query= { “TAG1”: “üğişi”, “TAG2”: “çöçödd”}
这些字符是“üğişi”和“çöçödd”UTF8字符。我需要转换此URL以获得响应。你能救我吗?
答案 0 :(得分:4)
使用-(NSString*)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding;
课程的NSString
例程。像这样:
NSString* url = @"http://www.test.com/query={\"tag1\":\"üğişi\",\"tag2\":\"çöçödd\"}";
NSString* urlEncoded = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];