CSV到JSON转换错误
我使用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对象的string。
你应该使用console.log('in json object', JSON.parse(jsonObj));
而不是console.log('in json object', jsonObj);
使其成为JSON对象forms。