转换CSV在JavaScript多维数组 [英] Convert CSV to multi dimensional array in Javascript

查看:482
本文介绍了转换CSV在JavaScript多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从使用jQuery的Ajax功能的CSV文件中读取数据。我一直在使用一个jQuery插件称为 jQuery的CSV < /一>将数据转换成一个阵列,但在Internet Explorer中的阵列为某种原因返回不同的密钥。

I'm reading data from a CSV file using jQuery's Ajax function. I have been using a Jquery plugin called Jquery CSV to convert the data into an array, but in Internet Explorer the array is returning different keys for some reason.

在code AJAX调用和插件处理数据是:

The code for the ajax call and the plugin processing the data was:

var ourOffices = new Array();
$.get(pathToData, function(data) {
   ourOffices = jQuery.csv("|")(data);
});

有人能指出我在正确的方向编码这种转换没有一个插件。

Can someone point me in the right direction to coding this conversion without a plug in.

字段之间用| 。每个记录是一个新的生产线,其中有值​​得注意的300。另外,这可能是为什么第一个插件行为不端,就是一些在CSV数据包含特殊字符,如重音。

The fields are separated by '|' . Each record is on a new line, of which there are 300. Also of note, which might be why the first plugin misbehaves, is that some of the data in the CSV contain special characters, like accents.

感谢。

P.S。我将提供一些示例数据,但它不适合这样做,对不起。

p.s. I would supply some example data, but its not appropriate to do so, sorry.

推荐答案

我相信你已经看到了插件分裂()注释不能在IE浏览器正常工作。 A ,, B.split()返回[A,B]而不是[A,,B]会是您的问题。

I'm sure you have seen the comment in the plugin split() doesn't work properly on IE. "a,,b".split(",") returns ["a", "b"] and not ["a", "", "b"] could that be your issue.

这篇关于转换CSV在JavaScript多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆