hi, i’m trying to conver json string to an object before insert to mongodb on final step, meteor return parse error from json i dont understand why, anyone can help me ?
console.log(contentpre);
{"id":1928, "auteur":"user1", "montant":5000, "prixunite":50000, "total": 250000}
{"id":1927, "auteur":"user1", "montant":5000, "prixunite":50000, "total": 250000}
{"id":1925, "auteur":"user1", "montant":5000, "prixunite":50000, "total": 250000}
{"id":1926, "auteur":"user1", "montant":5000, "prixunite":50000, "total": 250000}
{"id":1924, "auteur":"user1", "montant":5000, "prixunite":50000, "total": 250000}
{"id":1921, "auteur":"user1", "montant":5000, "prixunite":50000, "total": 250000}
{"id":1923, "auteur":"user1", "montant":5000, "prixunite":50000, "total": 250000}
I got this json, when i try to use json parse before collection insert meteor return
Meteor method import json result from phantomjs
Meteor.methods({
runTestsellorderhadronium: function(options){
command = spawn(phantomjs.path, ['assets/app/phantomDriversellorder.js']);
command.stdout.on('data', function (data) {
var contentpre = String(data);
console.log(contentpre);//works fine
var substringcontent = contentpre.substring(0,6);
if(substringcontent === '{"id":'){
var myobj = JSON.parse(contentpre, function(k, v){});
console.log(myobj);//dont work
}
});
command.stderr.on('data', function (data) {
console.log('stderr sellorderhadronium: ' + data);
});
command.on('exit', function (code) {
console.log('sellorderhadronium child process exited with code ' + code);
});
}
});
Meteor return an error when parsing json result from phantomjs
=> Exited with code: 8 W20160422-22:40:05.616(2)? (STDERR) W20160422-22:40:05.619(2)? (STDERR) undefined:2 W20160422-22:40:05.619(2)? (STDERR) {"id":1927, "auteur":"user1", "montant":5000, "prixunite":50000, "t W20160422-22:40:05.619(2)? (STDERR) ^ W20160422-22:40:05.619(2)? (STDERR) SyntaxError: Unexpected token { W20160422-22:40:05.620(2)? (STDERR) at Object.parse (native) W20160422-22:40:05.620(2)? (STDERR) at Socket.<anonymous> (server/server.js:28:20) W20160422-22:40:05.620(2)? (STDERR) at Socket.emit (events.js:95:17) W20160422-22:40:05.620(2)? (STDERR) at Socket.<anonymous> (_stream_readable.js:765:14) W20160422-22:40:05.620(2)? (STDERR) at Socket.emit (events.js:92:17) W20160422-22:40:05.621(2)? (STDERR) at emitReadable_ (_stream_readable.js:427:10) W20160422-22:40:05.621(2)? (STDERR) at emitReadable (_stream_readable.js:423:5) W20160422-22:40:05.621(2)? (STDERR) at readableAddChunk (_stream_readable.js:166:9) W20160422-22:40:05.622(2)? (STDERR) at Socket.Readable.push (_stream_readable.js:128:10) W20160422-22:40:05.622(2)? (STDERR) at Pipe.onread (net.js:529:21)