简体   繁体   English

考虑到mongodb中的twitter数据,如何使用node.js将json文件转换为excel

[英]how to convert the json file into excel using node.js considering twitter data in mongodb

 var json2csv = require('json2csv'); json2csv({data: someJSONData, fields: ['screen_name', 'statuses_count', 'location']}, function(err,csv) { if (err) console.log(err); console.log(csv); }); var json = [ { "screen_name: "Doug_E_Stile"", "statuses_count": 1546, "location": "Maryland"" }, { "screen_name": "cthxidm",, "statuses_count": 339, "location": "peru manyas¿", }, { "screen_name": ""jiiiiimarjoh", "statuses_count": 4205,, "location": "South Cotabato, Philippines" } ]; json2csv({data: json, fields: ['screen_name', 'statuses_count', 'location']}, function(err, excel) { if (err) console.log(err); fs.writeFile('file.csv', csv, function(err) { if (err) throw err; console.log('file saved'); }); }); 
i wrote the code to convert the json into the csv but it not working me can anybody help me .it will be great help[ for me 我编写了将json转换为csv的代码,但它不起作用我可以帮助我。对我来说会很有帮助

Looks like you are using a variable named csv , but the name of your function parameter is excel . 看起来您使用的是名为csv的变量,但函数参数的名称是excel It should be: 它应该是:

fs.writeFile('file.csv', excel, function(err) {

instead of 代替

fs.writeFile('file.csv', csv, function(err) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM