[IOS] URL encoding and decoding

Source: Internet
Author: User

1. First look at what is URL encoding (string with%22 similar to this)

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 "

Decode the URL

decoding

NSString *str2 = [str stringbyremovingpercentencoding]; (iOS9.0 (including 9.0) use)

  NSString *str2 = [str stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; (use below iOS9.0)

Encode the URL

Coding

NSString *STR3 = [str2 stringbyaddingpercentencodingwithallowedcharacters: [nscharacterset  Urlqueryallowedcharacterset]]; (iOS9.0 (including 9.0) use)

  NSString *STR3 = [str2 stringbyaddingpercentescapesusingencoding:nsutf8stringencoding]; (use below iOS9.0)

[IOS] URL encoding and decoding

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.