• 将string转换成UTF8在进行请求


    在请求服务器时,如果参数中带有中文字符。就会报参数格式错误,需要将其转换成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],

  • 相关阅读:
    elasticsearch客户端连接选择
    logstash5.x配置
    git操作
    Linux的crontab
    让MySQL支持中文
    Python装饰器(decorator)
    Python类的探讨
    Python对象(译)
    Python基础-作用域和命名空间(Scope and Namespace)
    Python输入输出(IO)
  • 原文地址:https://www.cnblogs.com/superchao8/p/3326721.html
Copyright © 2020-2023  润新知