直接贴上代码:

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<script language="javascript" src="jquery-1.8.3.min.js"></script>
<script language="javascript" src="csv.js"></script>
<script language="javascript" type="text/javascript">
function importXLS(){
if (!(window.File || window.FileReader || window.FileList || window.Blob)) {
alert('请使用Chrome浏览器!');
}
var files = $('input[name="fileTrans"]').prop('files');//获取到文件列表 if(files.length == 0){
alert('请选择文件');
return;
}else{
var reader = new FileReader();//新建一个FileReader
reader.readAsText(files[0], "gbk");//读取文件
reader.onload = function(evt){ //读取完文件之后会回来这里
var fileString = evt.target.result;
var a = CSV.parse(fileString, {
header: ['username', 'pay_money', 'pay_type']
});
      
console.log(a);
}
}
}
</script>
</head>
<body>
<input type="file" name="fileTrans" id="f" />
<input type="button" id="b" value="import" onclick="if(f.value=='')alert('请选择csv文件');else importXLS()" />
</body>
</html>

  这里用到了两个类:

FileReader();
CSV();
基本上能够兼容谷歌和360浏览器。 花了半天时间研究,如果你喜欢就加我好友吧。

jquery读取csv文件并用json格式输出的更多相关文章

  1. js读取csv文件为json显示

    摘要: 前面分享了用js将json数据下载为csv文件,方便后期管理.但是对于测试人员更希望能够以页面的形式展现任务,所以就做了一个将csv文件展现在页面上的例子. 代码: <!DOCTYPE ...

  2. 【转载】JsonLayout log4j2 json格式输出日志

    JsonLayout log4j2 json格式输出日志 如果日志输出时,想改变日志的输出形式为Json格式,可以在log4j2.xml中使用JsonLayout标签,使日志输出格式为Json格式. ...

  3. python之模块csv之 读取CSV文件(reader和DictReader2个方法)

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #读取CSV文件(reader和DictReader2个方法) import csv #csv文件,是一种常用 ...

  4. C++ 把数组数据存入 CSV 文件,以及读取 CSV 文件的数据

    1. CSV-百度百科 2. 代码 #pragma once //Microsoft Visual Studio 2015 Enterprise #include<iostream> #i ...

  5. 《手把手教你》系列技巧篇(六十九)-java+ selenium自动化测试 - 读取csv文件(详细教程)

    1.简介 在实际测试中,我们不仅需要读取Excle,而且有时候还需要读取CSV类的文件.如何去读取CSV的文件,宏哥今天就讲解和分享一下,希望对你能够有所帮助.前面介绍了如何读取excel文件,本篇介 ...

  6. sparkR读取csv文件

    sparkR读取csv文件 The general method for creating SparkDataFrames from data sources is read.df. This met ...

  7. VB6.0 读取CSV文件

    最近做了一个Upload文件的需求,文件的格式为CSV,读取文件的方法整理了一下,如下: 1.先写了一个读取CSV文件的Function: '读取CSV文件 '假设传入的参数strFile=C:\Do ...

  8. Python 读取csv文件到excel

    朋友问我如何通过python把csv格式的文件另存为xls文件,自己想了想通过读取csv文件然后再保存到xls文件中即可,也许还有其他简单的方法,但这里也为了练习python语法及其他知识,所以采用了 ...

  9. 转换成CSV文件、Word、Excel、PDF等的方法--读取CSV文件的方法

    1. 转换成CSV文件: http://www.dotnetgallery.com/lab/resource93-Export-to-CSV-file-from-Data-Table-in-Aspne ...

随机推荐

  1. LeetCode Word Pattern (模拟)

    题意: 给出一个模式串pattern,再给出一个串str,问str的模板是否是pattern. 思路: 注意点:只要对于所有pattern[i]相同的i,str中对应的所有words[i]也必须相同, ...

  2. 利用HTML5云存储实现模拟对比投票效果

    <!DOCTYPE HTML> <html> <head> <title>模拟对比投票效果</title> <meta name=&q ...

  3. IE6 IE8下背景图片不显示问题

    更改background:url()no-repeat; 去掉no-repeat即可解决问题!

  4. java设定窗口步长,依次统计窗口内数值总和

    import java.util.Arrays; public class test2 { public static void main(String[] args) { int winSize = ...

  5. 高效而轻松的sed命令

    sed(stream editor)是一款高效的流编辑器,它一次只处理一行内容,处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的 ...

  6. Android开源项目大全之工具库

    http://www.neast.cn/forum.php?mod=viewthread&tid=5487&fromuid=5

  7. error: Error retrieving parent for item: No resource found that matches the given name &#39;Theme.AppCompat.Light&#39;.,appcompatv7

    error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCom ...

  8. 软件或jar包等名字里的GA意思

    首页 > 转贴的文章 > 软件的版本"GA"代表什么意思?如MyEclipse 5.0 GA   软件的版本"GA"代表什么意思?如MyEclips ...

  9. HDU 1159 Common Subsequence

    HDU 1159 题目大意:给定两个字符串,求他们的最长公共子序列的长度 解题思路:设字符串 a = "a0,a1,a2,a3...am-1"(长度为m), b = "b ...

  10. DELPHI相应鼠标滚轮

    在鼠标的MouseWheel事件里写入以下内容 if WheelDelta < 0 then    SendMessage(scrollBox1.Handle, WM_VSCROLL, SB_L ...