Recently I have just written a JSON data export to generate an Excel file, By the way, using Filesaver.js to export other files, one of the points to note is that when the export is a JSON file or TXT file, the exported content if the string, especially when the exported data is JSON data, remember to turn a. Well, not much to say, directly on a small demo, as follows:
:
Https://github.com/eligrey/FileSaver.js
1 <!DOCTYPE HTML>2 <HTML>3 4 <Head>5 <MetaCharSet= "UTF-8">6 <title>Export generate JSON file and text</title>7 <Scriptsrc= "Js/filesaver.min.js"></Script>8 </Head>9 Ten <Body> One <Buttononclick= "Downloadjson (students)">Export Build JSON file</Button> A <Buttononclick= "Downloadtext (students)">Export generated text</Button> - </Body> - <Script> the varStudents= [{ - "name": "Xiao Ming 1", - " Age": "6", - "Sex": "male", + "Height": " -" - }, { + "name": "Xiao Ming 2", A " Age": "7", at "Sex": "male", - "Height": " -" - }, { - "name": "Xiao Ming 3", - " Age": "8", - "Sex": "male", in "Height": " the" - }]; to //Export Build JSON file + functionDownloadjson (data) { - varblob= NewBlob ([Json.stringify (data)], {type:"" }); the saveAs (BLOB,"Hello.json"); * } $ //Export generated textPanax Notoginseng functionDownloadtext (data) { - varblob= NewBlob ([Json.stringify (data)], {type:"Text/plain;charset=utf-8" }); the saveAs (BLOB,"Hello.txt"); + } A the </Script> + - </HTML>
Filesaver.js exporting JSON files and text