第一个问题,
我试图使用csvtojson模块从csv文件中获取一个JSON对象。
除了我得到的JSON对象之外,所有东西都正常工作,其中有对象键:
预期结果:
{
{"key": "value",
"other_key": "other_value"
},
{"key": "value",
"other_key": "other_value"
}
}获得:
{
1:{
"key": "value",
"other_key": "other_value
},
2:{
"key": "value",
"other_key": "other_value
}
}我创建JSON对象的代码如下所示:
csv({delimiter:";" }).fromFile(csv_path+name_csv)The文件如下:
TITLE;TITLE2;TITLE3;TITLE4;TITLE5
string;string;int;string;int
string;string;int;string;int发布于 2020-02-03 12:18:52
考虑这一执行:
const csv = require('csvtojson')
var csvStr = `TITLE;TITLE2;TITLE3;TITLE4;TITLE5
string;string;int;string;int
string;string;int;string;int`
csv({
delimiter:";"
})
.fromString(csvStr)
.then((csvRow)=>{
console.log(csvRow)
})它输出一个对象数组:
[ { TITLE: 'string', TITLE2: 'string', TITLE3: 'int', TITLE4: 'string', TITLE5: 'int' }, { TITLE: 'string', TITLE2: 'string', TITLE3: 'int', TITLE4: 'string', TITLE5: 'int' } ]
https://stackoverflow.com/questions/60038838
复制相似问题