我玩弄之旅上的節點,我只意識到路由器解釋JSON請求對象爲具有空值的鍵值:JSON之旅中的node.js
換句話說,當我發佈到服務器的JSON對象我得到如下:
http://127.0.0.1:3000/> post /events
... {url : "test"}
HTTP/1.1 200 OK
Date: Tue, 21 Feb 2012 00:42:38 GMT
Server: journey/0.4.0
Content-Type: application/json;charset=utf-8
Content-Length: 67
Connection: keep-alive
{
event: {
_id: '10tPxx',
resource: 'Event',
{url : "test"}: ''
}
}
正如你可以看到整個對象被視爲一個字符串。
這裏是我的旅程相關的代碼:
exports.createRouter = function(resource){
var router = new (journey.Router)({
api: 'basic'
});
router.path(/\/events/, function(){
....
this.post().bind(function(res, event){
console.log(event);
resource.create(event, function(err, result){
if(err){
return res.send(500, {}, {error: err.error});
}
res.send(200, {}, { event: result});
});
});
...
});
return router;
};
控制檯的打印輸出:
{ '{url : "test"}': '' }
怎麼可能是錯的?
當你發佈時,你是否將'Content-Type'請求頭設置爲'application/json'?它看起來像使用'querystring.parse'解析json而不是'JSON.parse'。 Revelant code:https://github.com/cloudhead/journey/blob/master/lib/journey.js#L331 – loganfsmyth 2012-02-21 01:21:58
http請求顯示:'Content-Type:application/json; charset = utf-8'我是隻使用http控制檯。 – mabounassif 2012-02-21 01:36:28
我不知道'; charset = utf-8'是否搞亂了正則表達式測試。 – mabounassif 2012-02-21 01:37:52