querystring.stringify(obj[, sep[, eq[, options]]])
添加於:v0.1.25
參數
obj<Object> 要序列化為 URL 查詢字符串的對象sep<string> 用於在查詢字符串中分隔鍵值對的子字符串。 默認:'&'。eq<string> 。用於分隔查詢字符串中的鍵和值的子字符串。 默認:'='。optionsencodeURIComponent<Function> 在查詢字符串中將 URL-unsafe 字符轉換為 percent-encoding 時使用的函數。 默認:querystring.escape()。
querystring.stringify() 方法通過遍曆對象的"own properties" 從給定的obj 生成一個 URL 查詢字符串。
它序列化在 obj 中傳遞的以下類型的值: <string>  |  <number>  |  <bigint>  |  <boolean>  |  <string[]>  |  <number[]>  |  <bigint[]>  |  <boolean[]>  數值必須是有限的。任何其他輸入值將被強製為空字符串。
querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' });
// Returns 'foo=bar&baz=qux&baz=quux&corge='
querystring.stringify({ foo: 'bar', baz: 'qux' }, ';', ':');
// Returns 'foo:bar;baz:qux'
默認情況下,查詢字符串中需要 percent-encoding 的字符將被編碼為 UTF-8。如果需要替代編碼,則需要指定替代 encodeURIComponent 選項:
// Assuming gbkEncodeURIComponent function already exists,
querystring.stringify({ w: '中文', foo: 'bar' }, null, null,
                      { encodeURIComponent: gbkEncodeURIComponent });
相關用法
- Node.js querystring.stringify()用法及代碼示例
 - Node.js querystring.unescape()用法及代碼示例
 - Node.js querystring.parse()用法及代碼示例
 - Node.js querystring.decode()用法及代碼示例
 - Node.js querystring.encode()用法及代碼示例
 - Node.js querystring.escape()用法及代碼示例
 - Node.js querystring.parse(str[, sep[, eq[, options]]])用法及代碼示例
 - 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.stringify(obj[, sep[, eq[, options]]])。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
