zoukankan      html  css  js  c++  java
  • [iOS]URL编码和解码

    1. 首先来看下什么样的是URL编码(字符串中带有%22 类似这样的)

    NSString *str = @"http://m.tuniu.com/api/home/data/index/c/%7B%22v%22%3A%227.1.0%22%2C%22ct%22%3A20%2C%22dt%22%3A1%2C%22p%22%3A11210%2C%22cc%22%3A2500%7D/d/%7B%22clientModel%22%3A%22HONOR+H30-L01%22%2C%22width%22%3A720%7D"

    把URL解码

    // 解码

      NSString *str2 = [str stringByRemovingPercentEncoding];  (iOS9.0(包括9.0)以上使用)

      NSString *str2 = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  (iOS9.0以下使用)

    把URL编码

    // 编码

      NSString *str3 = [str2 stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; (iOS9.0(包括9.0)以上使用)

      NSString *str3 = [str2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  (iOS9.0以下使用)

  • 相关阅读:
    (转载)linux 常用命令
    视图view
    Mysql增删改查
    mysql最基础命令
    mysql的基本操作
    (转载)RHEL7(RedHat 7)本地源的配置
    (转载)Linux之虚拟机 rehl7的ip
    js 基本
    java Servlet
    java Tttp协议和Tomcat
  • 原文地址:https://www.cnblogs.com/lidongxu/p/5153785.html
Copyright © 2011-2022 走看看