node. JS (quad)--querystring module

Source: Internet
Author: User

When parsing a URL, you can use a querystring to parse the URL query into an object

In the foreground also encountered in the background development is the processing of parameters we need to pass different use of parameters appended to the URL address sent to the server and the server to be a string parameter string does not know the number, parameters, parameter name

This requires a way to put the parameters in one place and put them inside the object.

We can traverse this object and get the value inside.

In Nodejs, QueryString provided us with this function.

Querystring.stringify (obj, [Sep], [eq])

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/8E/F6/wKiom1jP1WjCWj-EAAAvcvMmY0s742.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1jp1wjcwj-eaaavcvmmy0s742.jpg "/>

The second parameter is the connector, which is & by default;

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/8E/F6/wKiom1jP1Y6RbBCqAAAt8SI0b3k568.jpg "title=" 36020170315204858576.jpg "alt=" Wkiom1jp1y6rbbcqaaat8si0b3k568.jpg "/>

The third parameter is: what is replaced by ":" In Query

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/8E/F4/wKioL1jP1a3QC3y5AAAyMBGPCuY817.jpg "title=" 36020170315204858576.jpg "alt=" Wkiol1jp1a3qc3y5aaaymbgpcuy817.jpg "/>

Querystring.parse (str, [Sep], [eq], [options])

Serialization and deserialization

Through the Querystring.parse method

The first argument is: the deserialized string

The second argument is: Delimiter

The third parameter is: the Query method

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/8E/F6/wKiom1jP1z2zY1fvAACDo5rsNbo964.jpg "title=" 36020170315204858576.jpg "alt=" wkiom1jp1z2zy1fvaacdo5rsnbo964.jpg "/> Only the format and parameter settings are correct to be parsed correctly.

Querystring.escape Escape
Querystring.unescape Reversal Righteousness


650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/8E/F4/wKioL1jP2AriUGHzAAAgBehpC2s326.jpg "title=" 36020170315204858576.jpg "alt=" Wkiol1jp2ariughzaaagbehpc2s326.jpg "/>


QueryString is also particularly useful, especially when dealing with a large number of parameters to pass the scene can help us save a lot of time

The ability to respond quickly to business needs is a small tool for handling parameters.


This article is from the "It Rookie" blog, make sure to keep this source http://mazongfei.blog.51cto.com/3174958/1908574

node. JS (quad)--querystring module

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.