URL converted to Dictionary dictionary

Source: Internet
Author: User

Through the online search, reference to other people's knowledge, (not to steal know, I myself did) I know I have a lot of shortcomings, I hope one day can stand in the pyramid point

The URL is:

woaiwodejiaxiang://cn.jiaxiang.zg/loader?dt=1254896584562&cityid=tr&devicenumber=13185058252& Userid=20985532&roletype=2&state=1&token=dad8fa595beda8306ea1aa01250aeb0&deviceimei= 3951545154614522

1.

NSString *urlstring = [nsstring stringwithformat:@ "%@", url];//convert URL to nsstring

Nsmutablearray *urlarray =[nsmutablearray arraywithobject: urlstring];//and placed in array

Nsrange range = [urlarray[0] rangeofstring:@ "?" ]; Get the question mark position after the question mark is the parameter list urlarray[0]: I have only one element in the array

NSString *propertys = [urlarray[0] substringfromindex:(int) range. Location]; Parameter list

Nsarray *subarray =[propertys componentsseparatedbystring:@ "&"];//Split the string, split by &,

2.

Nsmutabledictionary *tempdic = [nsmutabledictionary dictionarywithcapacity:8];/ /8 is my URL has 8 parameters the most always get the dictionary has 8 key value pairs

For (int j = 0; j<subarray. Count; j + +) {

nsarray *dicarray = [Subarray[j] componentsseparatedbystring:@ "="];//equal sign "=" is used to split the key value pair

[Tempdic setobject:d icarray[1] forkey:d icarray[0]];//Add a key-value pair to the dictionary (I refer to someone else's)

}

NSLog(@ " print parameter list generated dictionary:\n%@", tempdic);//Dictionary of output conversions

{
"? dt" = 1254896584562;
Cityid = Gy;
Deviceimei = 3951545154614522;
DeviceNumber = 13185058252;
Roletype = 1;
state = 1;
token = dad8fa595beda8306ea1aa01250aeb0;
UserId = 20985532;
}

URL converted to Dictionary dictionary

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.