node. JS QueryString Module

Source: Internet
Author: User

QueryString is primarily used to manipulate and parse strings. A total of four methods: Querystring.parse,querystring.stringify,querystring.escape,querystring.unescape.

Before using QueryString, Requery comes in: const QueryString = require ("querystring");

You can then use the four methods described above:

1.querystring.parse method: String is deserialized to an object

Querystring.parse (str,separator,eq,options)

1) STR is a string that needs to be deserialized;

2) separator is a split character (default is ' & '), can be omitted;

3) EQ is used to divide the key and the value of the symbol (such as: Name=sophiehui, can be omitted, the default is ' = ');

4) options are used to set the Maxkeys and decodeURIComponent properties, Maxkeys is used to set the maximum number of pairs of key-value pairs, pass a number value, the default is 1000, if you pass in a 0, do not limit the amount of key-value pairs The decodeuricomponent is used to decode a string containing%, and the default value is Querystring.unescape.

For example: Querystring.parse ("name=sophiehui&interest=" Music "&interest=" reading "," & "," = ", {maxkeys:2}); The return value is: {name: ' Whitemu ', Sex: ' Man '}

2.querystring.stringify: Serializes an object to a string

Querystring.stringify (obj,separator,eq,options)

1) Obj: The object that needs to be serialized;

2) separator is a split character (default is ' & '), can be omitted;

3) EQ is used to divide the key and the value of the symbol (such as: Name=sophiehui, can be omitted, the default is ' = ');

4) Options pass in an object that sets the encodeURIComponent property, encodeURIComponent is a functong, Set an unsafe URL as a percentage (the default is Querystring.escape ())

For example: Querystring.stringify ({name: ' Sophiehui ', interest: [' music ', ' reading ']}, "&", "="); The return value is: ' Name&sophiehui =interest&music=interest&reading '

3.querystring.escape: Encode the passed-in% string

Querystring.escape (str)

Querystring.escape ("name=2,6"); return to ' name%3d2%3c6 '

3.querystring.unescape: Decoding an incoming% string

Querystring.unescape (str)

Querystring.unescape ("Name%3d2%3c6"); return to "name=2,6"

node. JS 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.