SyntaxError:无法parsingJSON正文:意外的标记o

我在Facebook上有一个Node.js Heroku应用程序,并且我一直在日志中find以下错误(当我实际尝试访问我的应用程序时,遇到了一个通用的应用程序错误):

2013-03-27T12:58:54+00:00 heroku[web.1]: Starting process with command `node web .js` 2013-03-27T12:58:55+00:00 app[web.1]: info: socket.io started 2013-03-27T12:58:55+00:00 app[web.1]: Listening on 6925 2013-03-27T12:58:56+00:00 heroku[web.1]: State changed from starting to up 2013-03-27T13:00:40+00:00 app[web.1]: ^ 2013-03-27T13:00:40+00:00 app[web.1]: undefined:1 2013-03-27T13:00:40+00:00 app[web.1]: 2013-03-27T13:00:40+00:00 app[web.1]: SyntaxError: Failed to parse JSON body: Un expected token o 2013-03-27T13:00:40+00:00 app[web.1]: at Object.parse (native) 2013-03-27T13:00:40+00:00 app[web.1]: at EventEmitter.emit (events.js:99:17) 2013-03-27T13:00:40+00:00 app[web.1]: SyntaxError: Unexpected token S 2013-03-27T13:00:40+00:00 app[web.1]: at EventEmitter.mixin._fireError (/app /node_modules/faceplate/node_modules/restler/lib/restler.js:192:10) 2013-03-27T13:00:40+00:00 app[web.1]: at IncomingMessage.parsers.json (/app/ node_modules/faceplate/node_modules/restler/lib/restler.js:367:9) 2013-03-27T13:00:40+00:00 app[web.1]: at EventEmitter.FaceplateSession.get ( /app/node_modules/faceplate/index.js:121:25) 2013-03-27T13:00:40+00:00 app[web.1]: at mixin._responseHandler (/app/node_m odules/faceplate/node_modules/restler/lib/restler.js:142:20) 2013-03-27T13:00:40+00:00 app[web.1]: at EventEmitter.mixin._encode (/app/no de_modules/faceplate/node_modules/restler/lib/restler.js:184:29) 2013-03-27T13:00:40+00:00 app[web.1]: at IncomingMessage.parsers.auto (/app/ node_modules/faceplate/node_modules/restler/lib/restler.js:356:21) 2013-03-27T13:00:40+00:00 app[web.1]: at mixin._responseHandler (/app/node_m odules/faceplate/node_modules/restler/lib/restler.js:140:16) 2013-03-27T13:00:40+00:00 app[web.1]: at EventEmitter.mixin._decode (/app/no de_modules/faceplate/node_modules/restler/lib/restler.js:156:7) 2013-03-27T13:00:41+00:00 heroku[web.1]: Process exited with status 1 2013-03-27T13:00:41+00:00 heroku[web.1]: State changed from up to crashed 

在我的服务器代码中,我正在使用JSON.stringify ,例如console.log(data + ': is in the tags table, with tag_id=' + JSON.stringify(result)); 其中result是从查询返回给Postgres数据库的答案。 然而,我从来没有使用JSON.parse ,所以这个错误是有点混乱,我也从来没有这个错误,直到今天(我的应用程序周一工作正常)。

另外令人困惑的是,如果我将JSON.stringify调用注释掉,我仍然会得到这个错误,所以任何想法都将非常感激!

根据https://github.com/heroku/faceplate/issues/26 ,我已经对我的代码进行了以下更改:

 function handle_facebook_request(req, res) { // if the user is logged in if (req.facebook.token) { async.parallel([ function(cb) { // query 4 friends and send them to the socket for this socket id req.facebook.get('/me/friends', { limit: 4 }, function(friends) { req.friends = JSON.parse(JSON.stringify(friends)); cb(); }); }, function(cb) { // query 16 photos and send them to the socket for this socket id req.facebook.get('/me/photos', { limit: 16 }, function(photos) { req.photos = JSON.parse(JSON.stringify(photos)); cb(); }); }, function(cb) { // query 4 likes and send them to the socket for this socket id req.facebook.get('/me/likes', { limit: 4 }, function(likes) { req.likes = JSON.parse(JSON.stringify(likes)); cb(); }); }, function(cb) { // use fql to get a list of my friends that are using this app req.facebook.fql('SELECT uid, name, is_app_user, pic_square FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1', function(result) { req.friends_using_app = JSON.parse(JSON.stringify(result)); cb(); }); } ], function() { render_page(req, res); }); } else { render_page(req, res); } } 

每一行与要求req.???? 例如req.friends就像req.friends = friends; 即我添加了JSON.parseJSON.stringify调用,没有任何改变。

如前所述,解决scheme可以在这里find: https : //github.com/heroku/faceplate/issues/26但应该指出,现在有更多的细节修复面板版本0.0.4(感谢我的提示!)