在请求服务器时,如果参数中带有中文字符。就会报参数格式错误,需要将其转换成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. 14条建议,使你的IT职业生涯更上一层楼

    摘要:升值为企业IT部门的领导者,是大部分IT技术人员职业生涯的最终追求.但从一般大众中脱颖而出,并非易事.仅仅把本职工作干好远远不够,还需要IT技术人员展示出投身于技术发展的奉献精神及伴随技术发展而 ...

  2. VPN column: PPTP(2)--PPTP协议解析

    zhu_hit原创,如需转载请注明出处.Thanks. PPTP协议大体上可以分为两部分:控制层连接和隧道,下面简要介绍两部分的功能.如果要详细了解PPTP协议请阅读RFC文档. 一. Control ...

  3. Java之iterator迭代器和iterable接口

    java.lang.Iterable java.util.Iterator Iterator是迭代器类,而Iterable是接口. 好多类都实现了Iterable接口,这样对象就可以调用iterato ...

  4. CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)

    题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行 ...

  5. 函数buf_ptr_get_fsp_addr

    #define FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID  34 /****************************************************** ...

  6. UVa 1363 (数论 数列求和) Joseph's Problem

    题意: 给出n, k,求 分析: 假设,则k mod (i+1) = k - (i+1)*p = k - i*p - p = k mod i - p 则对于某个区间,i∈[l, r],k/i的整数部分 ...

  7. hud 3336 count the string (KMP)

    这道题本来想对了,可是因为hdu对pascal语言的限制是我认为自己想错了,结果一看题解发现自己对了…… 题意:给以字符串 计算出以前i个字符为前缀的字符中 在主串中出现的次数和 如: num(aba ...

  8. Java [Leetcode 40]Combination Sum II

    题目描述: Given a collection of candidate numbers (C) and a target number (T), find all unique combinati ...

  9. 【转】COCOS2D-X之CCHttpRequest下载图片Demo

    #include "pthread.h" #pragma comment(lib,"libcurl_imp.lib") #pragma comment(lib, ...

  10. EntityFramework版本下载和更新

    安装指定版本的Package(例如:EntityFramework 5.0): PM> Install-Package EntityFramework -ProjectName MusicSto ...