iOS remove special characters from URL string [closed]

扶醉桌前 提交于 2019-12-13 09:40:34

问题


I want to call this URL using NSURLRequest:

http://www.test.com/query={"tag1":"üğişi","tag2":"çöçödd"}

These characters which are "üğişi" and "çöçödd" UTF8 character. I need to convert this URL to get response. Can you help me?


回答1:


Use the -(NSString*)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding; routine of th NSString class. Like so:

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

Here you can find more...



来源:https://stackoverflow.com/questions/11965990/ios-remove-special-characters-from-url-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!