Method of extracting parameters in URL (converted to JSON format)

Source: Internet
Author: User

Let's go straight to the code.

//The parameters in the URL are captured and replaced with the JSON format function serilizeurl (URL) {var urlobject={}; 1. Is the regular match for? The End if (/\?/.test (URL)) {//substring intercepts the string between the specified position,//The first value is the starting subscript, the second one does not write,//does not write until the last//2. Intercept? The thing behind var urlstring = url.substring (Url.indexof ('? ')        +1)//3. Add & Remove to array var Urlarray = Urlstring.split ("&"); 4. Traversing the array for (Var i=0;i<Urlarray. length;i++) {var Urlitem= Urlarray[i]; //Cut VAR item again=urlitem[i].split (' = '); //Assign Value urlobject[item[0]]=item[1]; } return urlobject; }//returns NULL if there is no match on it;

My code comments are more detailed, mainly to give beginners a reference.

Method of extracting parameters in URL (converted to JSON format)

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.