【发布时间】:2016-02-26 12:49:42
【问题描述】:
我正在尝试从 Chrome 应用程序“邮递员”通过 POST 发送 JSON 对象。
如果我将header设置为'Content-Type: text/plain',那么另一边的输出就是一个空对象:
{}
如果我将标头设置为Content-Type: application/json,我会收到以下响应...
'错误:无效的 json'。
key设置为ingredients,value设置为:
{ ["name" : "num1", "quantity" : "5"], ["name" : "num2", "quantity" : "2"], [ "name" : "num3", "quantity" : "8"]}
我在这里抓住了它:
router.post('/add', jsonParser, function( req, res ) {
if (!req.body) return res.sendStatus(400);
console.log( req.body );
});
【问题讨论】:
-
你能详细说明什么是jsonParser吗?像
var jsonParser = bodyParser.json()吗?
标签: javascript json node.js express body-parser