美文网首页📚苹果
iOS URL中含有中文处理 url出现特殊字符处理

iOS URL中含有中文处理 url出现特殊字符处理

作者: Morgan7 | 来源:发表于2018-08-24 10:34 被阅读0次
//直接访问此url会访问失败 
//原因 掺杂中文uincode 20180813150735_\U5de5\U7a0b\U5e08\U5934\U50cf.png 
NSString *str = @"http://xxxxxx.com/uploads/image/20180813/20180813150735_\U5de5\U7a0b\U5e08\U5934\U50cf.png";
//使用stringByAddingPercentEncodingWithAllowedCharacters处理
NSString *headImgURL = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet  URLQueryAllowedCharacterSet]];
NSLog(@"%@",headImgURL);//http://xxxxxx.com/uploads/image/20180813/20180813150735_%E5%B7%A5%E7%A8%8B%E5%B8%88%E5%A4%B4%E5%83%8F.png

参考文章
https://www.jianshu.com/p/21a21866e379
https://nshipster.cn/nscharacterset/

相关文章

网友评论

    本文标题:iOS URL中含有中文处理 url出现特殊字符处理

    本文链接:https://www.haomeiwen.com/subject/ibcbiftx.html