在请求服务器时,如果参数中带有中文字符。就会报参数格式错误,需要将其转换成UTF8

@interface NSString (NSURLUtilities)

/* Adds all percent escapes necessary to convert the receiver into a legal URL string.  Uses the given encoding to determine the correct percent escapes (returning nil if the given encoding cannot encode a particular character).  See CFURLCreateStringByAddingPercentEscapes in CFURL.h for more complex transformations

*/

- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc;

/* Replaces all percent escapes with the matching characters as determined by the given encoding.  Returns nil if the transformation is not possible (i.e. the percent escapes give a byte sequence not legal in the given encoding).  See CFURLCreateStringByReplacingPercentEscapes in CFURL.h for more complex transformations

*/

- (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)enc;

@end

代码如下:

@"keyword": [searchSoft.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],

将string转换成UTF8在进行请求的更多相关文章

  1. GB2312转换成UTF-8与utf_8转换成GB2312

    本文转载:http://www.cnblogs.com/jonhson/archive/2010/08/10/1796536.html /// <summary> /// utf_8转换成 ...

  2. gb2312提交的url编码转换成utf8的查询

    使用场景,当一网站是gb2312的编码向另一个是utf8的网站提交查询 如:http://search.chinayq.com/?key=%C0%D6%C6%F7 其中key为gb2312的url编码 ...

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

    在iOS开发中,特别是在对Web服务调用的时候,经常会遇到请求参数为中文的情况,那么这时候就需要将Url转成UTF-8编码才能进行请求.使用stringByAddingPercentEscapesUs ...

  4. 把ANSI格式的TXT文件批量转换成UTF-8文件类型

    把ANSI格式的TXT文件批量转换成UTF-8文件类型 Posted on 2010-08-05 10:38 moss_tan_jun 阅读(3635) 评论(0) 编辑 收藏 #region 把AN ...

  5. android String 类型转换成UTF-8格式

    在android开发中,有时候会遇到汉字乱码的问题,在这个时候,吧String串加一个编码格式转换,转换成UTF-8的格式就可以了 public static String toUtf8(String ...

  6. 在C#中将String转换成Enum:

    一:  在C#中将String转换成Enum: object Enum.Parse(System.Type enumType, string value, bool ignoreCase); 所以,我 ...

  7. C# 字符串string类型转换成DateTime类型 或者 string转换成DateTime?(字符串转换成可空日期类型)

    在c#中,string类型转换成DateTime类型是经常用到的,作为基本的知识,这里在此做个小结.一般来说可以使用多种方法进行转换,最常用的就是使用Convert.ToDateTime(string ...

  8. LoadRunner 如何将英文的字符串转换成UTF-8格式的字符串?

    7.48  如何手动转换字符串编码 1.问题提出 如何将英文的字符串转换成UTF-8格式的字符串? 2.问题解答 可以使用lr_convert_string_encoding函数将字符串从一种编码手动 ...

  9. string转换成color转

    string转换成color             string col = "#FF8400";            this.BackColor = System.Draw ...

随机推荐

  1. WPF 中如何使用第三方控件 ,可以使用WindowsFormsHost 类

    允许在 WPF 页面上承载 Windows Forms控件的元素. 命名空间:   System.Windows.Forms.Integration 程序集:   WindowsFormsIntegr ...

  2. git bash中带空格的文件夹以及文件的处理

    空格用'\ '表示,输入的时候,是不需要单引号的 total 338drwxr-xr-x 9 Administ Administ 4096 Aug 24 23:53 HDTHelperdrwxr-xr ...

  3. Android开发之多媒体编程之加载大分辨率图片

    Android中图片占用内存的大小=图片的总像数*每个像数占用的大小. Android保存图片像素信息使用ARGB,意思是每个像素占用4个字节. 以分辨率为2400*3200的图片来说,加载到Andr ...

  4. pylinter could not automatically determined the path to `lint.py`

    先关闭Sublime Text 1) 到官网先下载pylinter,http://www.logilab.org/project/pylint,然后解压缩,拷贝到C盘,目录为C:\pylint-1.0 ...

  5. NOI2005维修数列

    剧恶心的splay…… 为什么在bzoj上是超时,在自己的电脑上测的是栈溢出…… ; maxc=; var n,m,i,j,y,root,x,posi,t,head:longint; ch:char; ...

  6. tar 命令打包,除了某个目录剩下的都打包

    tar czvf beifen.tar.gz  ./webdata  --exclude webdata/uploadfiles

  7. Hibernate4.x之映射关系--继承映射

    Hibernate的继承映射可以理解为持久化类之间的继承关系.例如:人和学生之间的关系.学生继承了人,可以认为学生是一个特殊的人,如果对人进行查询,学生的实例也将被得到. Hibernate支持以下三 ...

  8. 使用busybox制作rootfs

    Build Busybox as a static binary(no shared libs),如果选择上,则busybox将以静态形式进行编译,否则将以动态方式编译.此外,还需要对交叉编译环境进行 ...

  9. Owasp Top 10 Security Risks for 2014

    A1-互联网泄密事件/撞库攻击 以大量的用户数据为基础,利用用户相同的注册习惯(相同的用户名和密码),尝试登陆其它的网站.2011年,互联网泄密事件引爆了整个信息安全 界,导致传统的用户+密码认证的方 ...

  10. 导入showb时候出错--2015-12-4

    [root@cache-02 ~]# /opt/coreseek/csftweb-bash: /opt/coreseek/csftweb: is a directory[root@cache-02 ~ ...