zoukankan      html  css  js  c++  java
  • 将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],

  • 相关阅读:
    php1
    element ui
    webpack
    vue-router
    vue实例相关2
    vue实例相关
    js笔记2
    js笔记
    不找工作,你的简历也要更新!
    除了做测试,我们还能做些什么呢?
  • 原文地址:https://www.cnblogs.com/superchao8/p/3326721.html
Copyright © 2011-2022 走看看