Export a Json object to a text File

前端 未结 3 1541
逝去的感伤
逝去的感伤 2021-02-02 18:09

I\'m trying to write a Json object (JsonExport) and I\'d like to write its content into a text file.

I\'m using max4live to export data from Audio DAW to Json in order t

3条回答
  •  死守一世寂寞
    2021-02-02 18:33

    If you have access to an already existing file, just link to it. You can specify what the downloaded file name will be like this:

    
        Download as JSON
    
    

    If needed, you could also write out the dataURI as well

     //Get the file contents
     var txtFile = "test.txt";
     var file = new File(txtFile);
     var str = JSON.stringify(JsonExport);
    
     //Save the file contents as a DataURI
     var dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(str);
    
     //Write it as the href for the link
     var link = document.getElementById('link').href = dataUri;
    

    Then just give the link an ID and a default href

    
        Download as JSON
    
    

提交回复
热议问题