querystring.parse(str[, sep[, eq[, options]]])
曆史
| 版本 | 變化 | 
|---|---|
| v8.0.0 | 現在可以正確解析多個空條目(例如   | 
| v6.0.0 | 返回的對象不再繼承自   | 
| v6.0.0、v4.2.4 | 
  | 
| v0.1.25 | 添加於:v0.1.25  | 
參數
str<string> 要解析的 URL 查詢字符串sep<string> 用於在查詢字符串中分隔鍵值對的子字符串。 默認:'&'。eq<string> 。用於分隔查詢字符串中的鍵和值的子字符串。 默認:'='。options<Object>decodeURIComponent<Function> 解碼查詢字符串中的百分比編碼字符時使用的函數。 默認:querystring.unescape()。maxKeys<number> 指定要解析的最大鍵數。指定0以刪除 key 計數限製。 默認:1000。
querystring.parse() 方法將 URL 查詢字符串 (str) 解析為鍵值對的集合。
例如,查詢字符串'foo=bar&abc=xyz&abc=123'被解析為:
{
  foo: 'bar',
  abc: ['xyz', '123']
}
querystring.parse() 方法返回的對象在原型上並非繼承自 JavaScript Object 。這意味著典型的 Object 方法,例如 obj.toString() 、 obj.hasOwnProperty() 和其他方法沒有定義並且不會起作用。
默認情況下,查詢字符串中的百分比編碼字符將被假定為使用 UTF-8 編碼。如果使用替代字符編碼,則需要指定替代 decodeURIComponent 選項:
// Assuming gbkDecodeURIComponent function already exists...
querystring.parse('w=%D6%D0%CE%C4&foo=bar', null, null,
                  { decodeURIComponent: gbkDecodeURIComponent });
相關用法
- Node.js querystring.parse()用法及代碼示例
 - Node.js querystring.unescape()用法及代碼示例
 - Node.js querystring.decode()用法及代碼示例
 - Node.js querystring.stringify(obj[, sep[, eq[, options]]])用法及代碼示例
 - Node.js querystring.encode()用法及代碼示例
 - Node.js querystring.escape()用法及代碼示例
 - Node.js querystring.stringify()用法及代碼示例
 - Node.js queueMicrotask(callback)用法及代碼示例
 - Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
 - Node.js http2.Http2ServerRequest request.url用法及代碼示例
 - Node.js request.socket用法及代碼示例
 - Node.js assert.notEqual(actual, expected[, message])用法及代碼示例
 - Node.js tlsSocket.authorized用法及代碼示例
 - Node.js zlib.deflateRaw()用法及代碼示例
 - Node.js http.IncomingMessage message.rawHeaders用法及代碼示例
 - Node.js Console用法及代碼示例
 - Node.js GM transparent()用法及代碼示例
 - Node.js URL.protocol用法及代碼示例
 - Node.js http.Agent.reuseSocket(socket, request)用法及代碼示例
 - Node.js fs.filehandle.datasync()用法及代碼示例
 - Node.js socket.bind()用法及代碼示例
 - Node.js v8.getHeapSpaceStatistics()用法及代碼示例
 - Node.js http2session.destroyed用法及代碼示例
 - Node.js http.ServerResponse response.statusCode用法及代碼示例
 - Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代碼示例
 
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 querystring.parse(str[, sep[, eq[, options]]])。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
