2014-10-27 25 views
0

我有一個POST處理程序:Express 3.x req.params是帶方括號的對象嗎?

app.use(express.bodyParser()); 
app.use(app.router) 

app.post('/api/auth/:service', function(req, res) { 
    console.log('req.params', req.params); 
    ... 

當我打印req.params我得到一個奇怪的現象:

req.params [ service: 'webui' ] 

它看起來像一個對象,但它有方括號。

什麼是req.params

根據http://expressjs.com/3x/api.html#req.params

This property is an array containing properties mapped to the named route 
"parameters". 

回答

0

原來JSON.stringify()滴陣列的所有的「參數」的屬性,只留下一個空數組。

由於JSON.stringify()是記錄過程的一部分,它使我困惑。

實施例:

$ node 
> var a = []; 
undefined 
> a.foo = 'foo'; 
'foo' 
> a 
[ foo: 'foo' ] 
> JSON.stringify(a); 
'[]'