'extended' 在 express 4.0 中是什么意思?
What does 'extended' mean in express 4.0?
我在我的应用中使用了 express 和 body-parser。
app.use(bodyParser.urlencoded({ extended: false }));
但是,'extended' 在 express 4.0 中是什么意思?
我找到了这个
extended - parse extended syntax with the qs module.
不过,我还是没明白是什么意思
来自 Body-Parser 文档:
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true).
和
The extended option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true). The "extended" syntax allows for rich objects and arrays to be encoded into the URL-encoded format, allowing for a JSON-like experience with URL-encoded. For more information, please see the qs library.
基本扩展允许您解析完整对象。
如果extended
是false
,则不能post"nested object"
person[name] = 'cw'
// Nested Object = { person: { name: cw } }
如果extended
是true
,你可以随心所欲。
When extended
property is set to true
, the URL-encoded data will
be parsed with the qs library.
相反,
when extended
property is set to false
, the URL-encoded data will
instead be parsed with the querystring library.
使用 `qs 库` 与 `querystring 库` 进行解析的区别
qs 库允许您从查询字符串创建 nested 对象。
var qs = require("qs")
var result = qs.parse("person[name]=bobby&person[age]=3")
console.log(result) // { person: { name: 'bobby', age: '3' } }
查询字符串库不支持从查询字符串创建嵌套对象。
var queryString = require("query-string")
var result = queryString.parse("person[name]=bobby&person[age]=3")
console.log(result) // { 'person[age]': '3', 'person[name]': 'bobby' }
qs 库将 not 过滤掉 '?'来自查询字符串。
var qs = require("qs")
var result = qs.parse("?a=b")
console.log(result) // { '?a': 'b' }
query-string 库会过滤掉'?'来自查询字符串。
var queryString = require("query-string")
var result = queryString.parse("?a=b")
console.log(result) // { a: 'b' }
app.use(bodyParser.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
更多信息,您可以参考, and npm compare qs vs query-string.
我在我的应用中使用了 express 和 body-parser。
app.use(bodyParser.urlencoded({ extended: false }));
但是,'extended' 在 express 4.0 中是什么意思?
我找到了这个
extended - parse extended syntax with the qs module.
不过,我还是没明白是什么意思
来自 Body-Parser 文档:
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true).
和
The extended option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true). The "extended" syntax allows for rich objects and arrays to be encoded into the URL-encoded format, allowing for a JSON-like experience with URL-encoded. For more information, please see the qs library.
基本扩展允许您解析完整对象。
如果extended
是false
,则不能post"nested object"
person[name] = 'cw'
// Nested Object = { person: { name: cw } }
如果extended
是true
,你可以随心所欲。
When
extended
property is set totrue
, the URL-encoded data will be parsed with the qs library.
相反,
when
extended
property is set tofalse
, the URL-encoded data will instead be parsed with the querystring library.
使用 `qs 库` 与 `querystring 库` 进行解析的区别
qs 库允许您从查询字符串创建 nested 对象。
var qs = require("qs") var result = qs.parse("person[name]=bobby&person[age]=3") console.log(result) // { person: { name: 'bobby', age: '3' } }
查询字符串库不支持从查询字符串创建嵌套对象。
var queryString = require("query-string") var result = queryString.parse("person[name]=bobby&person[age]=3") console.log(result) // { 'person[age]': '3', 'person[name]': 'bobby' }
qs 库将 not 过滤掉 '?'来自查询字符串。
var qs = require("qs") var result = qs.parse("?a=b") console.log(result) // { '?a': 'b' }
query-string 库会过滤掉'?'来自查询字符串。
var queryString = require("query-string") var result = queryString.parse("?a=b") console.log(result) // { a: 'b' }
app.use(bodyParser.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
更多信息,您可以参考