Js reads the csv file and displays it in json format, csvjson
Abstract:
We have discussed how to use js to download json data into a csv file for later management. However, testers prefer to display tasks on pages, so an example of displaying csv files on pages is provided.
Code:
Copy codeThe Code is as follows:
<! 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> convert CSV to 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>
:
Note: The preceding example requires a service environment.