js讀取csv檔案為json顯示

來源:互聯網
上載者:User

標籤:

摘要:

  前面分享了用js將json資料下載為csv檔案,方便後期管理。但是對於測試人員更希望能夠以頁面的形式展現任務,所以就做了一個將csv檔案展現在頁面上的例子。

 代碼:
<!DOCTYPE html><html><head>    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />    <title>csv</title>    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>    <script src="./papaparse.min.js"></script>    <style>        html,body{            font-size: 14px;            font-family: ‘Microsoft Yahei‘,Tahoma,Verdana,simsun,sans-serif;        }        table {width: 85%;margin: 30px auto;}    </style></head><body>    <table id="table" border="1">        <caption>CSV轉JSON</caption>        <thead>            <tr>                <th>Vehicle</th>                <th>Date</th>                <th>Location</th>                <th>Speed</th>            </tr>        </thead>        <tbody>        </tbody>    </table>    <script>    Papa.parse(‘./Result.csv‘, {        download: true,        complete: function(results) {            var data = results.data, html;            for(var i = 1, _l = data.length-1; i < _l; i++) {                var item = data[i];                html += ‘<tr><td>‘+item[0].substring(1)+‘</td><td>‘+item[1].substring(1)+‘</td><td>‘+item[2].substring(1)+‘</td><td>‘+item[3].substring(1)+‘</td></tr>‘;            }            $(‘#table tbody‘).append(html);        }    });    </script></body></html>

 

:

注意:上面的例子需要服務環境

附錄:

  https://github.com/mholt/PapaParse

 

js讀取csv檔案為json顯示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.