json2csv节点模块

时间:2017-09-08 15:32:31

标签: node.js

我在使用json2csv节点模块(https://www.npmjs.com/package/json2csv)时遇到问题。这是我的代码:

var fields = ['originCountry', 'destinationCountry', 'avgNationalTuitionFee'];
    var outputResult = [
     {
      "outputOriginCountry" : "Denmakr", //origin,
      "outputDestinationCountry" : "Germany", //destination,
      "outputAvgTuitionFee" : "10000"
     },
     {
      "outputOriginCountry" : "Italy", //origin,
      "outputDestinationCountry" : "Spain", //destination,
      "outputAvgTuitionFee" : "5000"
     }
    ];

    var csv = json2csv({ data: outputResult, fields: fields });
    console.log("Csv file contains " + csv)

    fs.writeFile('analysis-output.csv', csv, function(err) {
      if (err) throw err;
      console.log('file saved');
    });

问题是输出为空,如图所示: enter image description here

但是,我不知道问题是什么。你有任何线索吗?

非常感谢!

0 个答案:

没有答案