Xin chào Tôi không hiểu tại sao tôi gặp lỗi này, tôi nghĩ rằng cuộc gọi lại đã được thực hiện khi dữ liệu đã được nhận, bất kỳ ý tưởng nào đến từ đâu? Cảm ơn rất nhiều!Cú pháp: Kết thúc bất ngờ của đầu vào tại Object.parse (bản địa) yêu cầu npm
Node lỗi:
SyntaxError: Unexpected end of input
at Object.parse (native)
tôi phân tích câu trả lời của cơ thể gửi nó cho một hàm tính toán trước khi gửi nó đến trang =/
var options = {
method: 'POST',
url: self.rippledataapiProxyHost.account_offers_exercised,
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body:parameters
};
var callback = function(error, response, body) {
if (error) {
console.log('error', error);
res.send(500, 'something went wrong');
}
console.dir("bodyyyyyyyy====>",body);
var rippleoffersexercised = new self.datacalcul.rippleoffersexercised;
var data = JSON.parse(body);
var datas = rippleoffersexercised.calculate(data);
res.status(response.statusCode).send(datas);
}
request(options, callback);
Đây là stack trace:
'bodyyyyyyyy====>'
SyntaxError: Unexpected end of input
at Object.parse (native)
at Request.callback [as _callback] (/home/francois/dev/ripplereport/webserver-newclientFrancois/server/middlewares/proxy/rippledataapiProxy.js:77:20)
at Request.self.callback (/home/francois/dev/ripplereport/webserver-newclientFrancois/node_modules/request/request.js:344:22)
at Request.emit (events.js:98:17)
at Request.<anonymous> (/home/francois/dev/ripplereport/webserver-newclientFrancois/node_modules/request/request.js:1239:14)
at Request.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/home/francois/dev/ripplereport/webserver-newclientFrancois/node_modules/request/request.js:1187:12)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:943:16
at process._tickCallback (node.js:419:13)
[gulp] [nodemon] app crashed - waiting for file changes before starting...
'console.dir (body)' hiển thị là gì? – mscdex
nó cho thấy đối tượng, điều này là lạ này là làm việc nhưng đôi khi nó bị treo không thể nói lý do tại sao –
'console.dir (cơ thể)' cho thấy một * đối tượng *? Nó sẽ hiển thị một chuỗi. Bạn có thể thử đặt 'json: true' trong các tùy chọn request() của bạn. – mscdex