张贴JSON来expression – 无效的JSON

我试图发表一些JSON到运行快递的节点服务器,但它一直告诉我JSON无效。 但它不是,它只是一个普通的旧对象。 目前我收到错误“意外的令牌我”

客户:

$.ajax({ contentType: 'application/json', type: "POST", url: "/admin", data: {id: '435ghgf545ft5345', allowed: true} }); 

服务器:

 var bodyParser = require('body-parser'); app.use(bodyParser({strict: false})); app.post('/admin', function(request, response) { console.log(request.body); }); 

我也尝试把bodyParser.json()作为postpath中的第二个参数,并得到错误“parsing无效的json”。 我不知道为什么。

此代码可以帮助您:

 var jsondataResource = JSON.stringify({id: '435ghgf545ft5345', allowed: true}); $.ajax({ type: 'POST', //GET or POST or PUT or DELETE verb async: false, url: '/admin', // Location of the service data: jsondataResource , //Data sent to server contentType: 'application/json', // content type sent to server dataType: 'json', //Expected data format from server processdata: true, //True or False crossDomain: true, success: function (msg, textStatus, xmlHttp) { result = msg; }, error: ServiceFailed // When Service call fails }); function ServiceFailed(result) { alert('Service call failed: ' + result.status + '' + result.statusText); Type = null; Url = null; Data = null; ContentType = null; DataType = null; ProcessData = null; }