<!DOCTYPE html>
<html lang="en">
<head>
	<title>excel转json</title>
	<meta charset="utf-8">
</head>
<body>
	<textarea ></textarea>
	<input type="button" value="转换"  />
	<textarea ></textarea>
	
	<input type="hidden"  />
	
	<script src="http://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript">
        var fgf = /\t/;
        function ctyperow() {
            fgf = $("#fgfstr").val() || fgf;
            var ctype = $("#ctype").val();
            var txt = $("#content").val();
            var datas = txt.split("\n");
            var html = "[\n";
            var keys = [];
            for (var i = 0; i < datas.length; i++) {
                var ds = datas[i].split(fgf);
                if (i == 0) {
                    if (ctype == "0") {
                        keys = ds;
                    } else {
                        html += "[";
                        for (var j = 0; j < ds.length; j++) {
                            html += '"' + ds[j] + '"';
                            if (j < ds.length - 1) {
                                html += ",";
                            }
                        }
                        html += "],\n";
                    }
                } else {
                    if (ds.length == 0)
                        continue;
                    if (ds.length == 1) {
                        ds[0] == "";
                        continue;
                    }
                    html += ctype == "0" ? "{" : "[";
                    for (var j = 0; j < ds.length; j++) {
                        var d = ds[j];
                        if (d == "")
                            continue;
                        if (ctype == "0") {
                            html += '"' + keys[j] + '":"' + d + '"';
                        } else {
                            html += '"' + d + '"';
                        }
                        if (j < ds.length - 1) {
                            html += ',';
                        }
                    }
                    html += ctype == "0" ? "}" : "]";
                    if (i < datas.length - 1)
                        html += ",\n";
                }
            }
            html += "\n]";
            $("#result").val(html);
        }
    </script>
</body>
</html> 

代码来自互联网

相关文章:

  • 2021-10-25
  • 2021-10-20
  • 2021-11-16
  • 2022-01-28
  • 2021-07-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2022-02-08
  • 2022-01-19
相关资源
相似解决方案