Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

在iOS中将string转成UTF-8编码

在iOS开发中,特别是在对Web服务调用的时候,经常会遇到请求参数为中文的情况,那么这时候就需要将Url转成UTF-8编码才能进行请求。
使用stringByAddingPercentEscapesUsingEncoding:方法可以将string转成UTF-8编码,
如下面代码

NSURL *url = [NSURL URLWithString: [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

posted on 2014-09-08 17:44  Sinner_Yun  阅读(278)  评论(0编辑  收藏  举报

导航