- JavaScript standard Reference Tutorial (Alpha)
- Draft II: node. js
- QueryString Module
QueryString Module
From the JavaScript standard reference tutorial (Alpha), by Ruan Feng
Directory
querystringModules are primarily used to parse query strings.
Querystring.parse ()
querystring.parse()method is used to parse a query string into a JavaScript object.
var str = ‘foo=bar&abc=xyz&abc=123‘;querystring.parse(str)// { foo: ‘bar‘, abc: [ ‘xyz‘, ‘123‘ ] }
parseMethod can accept four parameters altogether.
querystring. Parse (str[, sep[, eq[, options
str: Query string to parse
sep: The delimiter between multiple key-value pairs, which defaults to&
eq: The delimiter between the key name and the key value, which defaults to=
options: Configuration object, which has two properties, decodeURIComponent is a function used to restore the encoded string, by default querystring.unescape() , the property specifies the maximum number of maxKeys properties to resolve, by default 1000 , if set to 0 represents the maximum quantity of an unrestricted attribute.
The previous example omits the next three parameters, and the complete invocation form is as follows.
querystring.parse( ‘w=%D6%D0%CE%C4&foo=bar‘, null, null, { decodeURIComponent: gbkDecodeURIComponent })
parseMethod can also be used to parse a generic string.
var str = ‘name:Sophie;shape:fox;condition:new‘;querystring.parse(str, ‘;‘, ‘:‘)// {// name: ‘Sophie‘,// shape: ‘fox‘,// condition: ‘new‘,// }
Message comments Powered byDisqus
Copyright Notice | Last modified on 2015-06-06
Nodejs-querystring Module