parse
const querystring = require('querystring')
var qs = 'x=3&y=4'
var parsed = querystring.parse(qs)
console.log(parsed) // [Object: null prototype] { x: '3', y: '4' }
stringify
const querystring = require('querystring')
var qo = {
x: 3,
y: 4
}
var parsed = querystring.stringify(qo)
console.log(parsed) // x=3&y=4
escape/unescape文章来源:https://www.toymoban.com/news/detail-727131.html
传入参数在 escape 包装下可以将参数中的有特殊字符进行转义,防止 sql 注入。文章来源地址https://www.toymoban.com/news/detail-727131.html
const querystring = require('querystring')
var str = 'id=3&city=北京&url=https://www.baidu.com'
var escaped = querystring.escape(str)
console.log(escaped) // id%3D3%26city%3D%E5%8C%97%E4%BA%AC%26url%3Dhttps%3A%2F%2Fwww.baidu.com
const querystring = require('querystring')
var str = 'id%3D3%26city%3D%E5%8C%97%E4%BA%AC%26url%3Dhttps%3A%2F%2Fwww.baidu.com'
var unescaped = querystring.unescape(str)
console.log(unescaped) // id=3&city=北京&url=https://www.baidu.com
到了这里,关于【Node.js】querystring 模块的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!