zoukankan      html  css  js  c++  java
  • iOS

    自iOS9以后字符串的解码方法  - (nullable NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc 就被

    - (nullable NSString *)stringByAddingPercentEncodingWithAllowedCharacters:(NSCharacterSet *)allowedCharacters方法给代替了。

    具体的实现的方法如下:

         //定义一个字符串

        NSString *str = @"http://apis.haoservice.com/weather?cityname=北京&key=c056e50a2bde4478a1a31ae491799607";

        //把字符串转换为NSCharacterSet类型

            NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:str];

       // 再根据NSCharacterSet类型转换字符串的中文为相应的编码,

            NSString *encodedValue = [str stringByAddingPercentEncodingWithAllowedCharacters:set];

             NSLog(@"%@",encodedValue);

     运行结果如下:

    encodedValue = http://apis.haoservice.com/weather?cityname=%E5%8C%97%E4%BA%AC&key=c056e50a2bde4478a1a31ae491799607。

     

  • 相关阅读:
    属性选择器
    Map
    tomcat 启动失败
    find for /f 分割字符串 bat
    oracle 1day
    scott lock
    oracle oracle sqldeveloper 12505 创建连接失败
    oracle sql developer 启动java.exe设置错误
    servlet post response.sendRedirect 乱码

  • 原文地址:https://www.cnblogs.com/liumu/p/5475707.html
Copyright © 2011-2022 走看看