Filesaver.js exporting JSON files and text

Source: Internet
Author: User
Tags ming

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.