大佬教程收集整理的这篇文章主要介绍了URL编码字符串,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
用这个 -
NsString *newCountryString = [country StringByAddingPercentEscapesUsingEnCoding:NSUTF8StringEnCoding];
此代码将使用给定的编码返回接收方的表示形式,以确定将接收方转换为合法URL字符串所需的转义百分比。
有关更多详细信息:https ://developer.apple.com/documentation/foundation/nsString/1415058-Stringbyaddingpercentescapesusin
在iOS 9中不推荐使用StringByAddingPercentEscapesUsingEnCoding。
[country StringByAddingPercentEnCodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]
country.addingPercentEnCoding( withAllowedCharacters: .urlHostAllowed)
有关更多详细信息:https ://developer.apple.com/documentation/foundation/nsString/1411946-StringbyaddingpercentenCodingwitwit?language=objc
我收到一个json数据对象,然后从中提取一个字符串
NSDictionary *jsonDictionary = [NSJSONserialization JSONObjectWithData:data
options:0
error:nil];
NSString *country=jsonDictionarY[@"address"][@"country"];
然后我尝试使该字符串适合在URL中使用
NSString *newCountryString = [country StringByreplacingoccurrencesOfString:@" "
withString:@"%%20"];
但它不起作用
以上是大佬教程为你收集整理的URL编码字符串全部内容,希望文章能够帮你解决URL编码字符串所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。