gpt4 book ai didi

javascript - csv 到 json 转换错误

转载 作者:可可西里 更新时间:2023-11-01 10:31:46 26 4
gpt4 key购买 nike

我使用 csvtojson 转换器来转换成 json 格式。

 var csvFileName = path; //path== filepath

var csvConverter = new Converter();

csvConverter.on("end_parsed", function (jsonObj) {

console.log('in json object', jsonObj);


});

csvConverter.from(csvFileName);

csvtojson 转换器转换成这种格式。

{ csvRows: 
[ { { 'id\tname\talias\tdescription\timages\tprice\tcompare_price\tcollections\tbrand\tquantity\tsku\tbarcode\tcategories\tpublish\tvariants\tstate\tavg_rating\tnum_reviews\tweight\tfree_product\toption_set': '525ba1b3f96404a56a000006\tbraclet12\tbraclet12\tundefined\t\t100\tundefined\tundefined\tundefined\tundefined\tundefined\tundefined\tundefined\t\t\t\t\t\t\t\t' }];

但我想要这种格式-

{ csvRows: 
[ { id: '51f21e7c60c058bc54000001',
name: 'dummy product',
alias: 'dummy-product1111111111',
description: 'Lorem Ipsumuuu',
images: '',
price: '55',
compare_price: 'undefined',
collections: 'undefined',
brand: 'undefined',
quantity: 'undefined',
sku: 'undefined',
barcode: 'undefined',
categories: '',
publish: '1',
variants: undefined,
state: undefined,
avg_rating: undefined,
num_reviews: undefined,
weight: undefined,
free_product: undefined,
option_set: undefined }]

知道如何实现吗?

非常感谢您的帮助和想法。

最佳答案

它返回 JSON 对象的字符串。

你应该使用 console.log('in json object', JSON.parse(jsonObj)); 而不是 console.log('in json object', jsonObj); 使其成为 JSON 对象形式。

关于javascript - csv 到 json 转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22525805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com