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