将Json对象导出到文本文件 [英] Export a Json object to a text File
问题描述
我正在尝试编写一个Json对象(JsonExport),我想将其内容写到一个文本文件中.
I'm trying to write a Json object (JsonExport) and I'd like to write its content into a text file.
我正在使用max4live将音频DAW中的数据导出到Json,以便导出到服务器,但是之后,我想在文本文件中看到整个Json对象:
I'm using max4live to export data from Audio DAW to Json in order to export to a server, but after that I would like to see the whole Json Object in a text file:
var txtFile = "test.txt";
var file = new File(txtFile);
var str = JSON.stringify(JsonExport);
file.open("write"); // open file with write access
file.write(str);
file.close();
编译器运行没有错误,但是我无法获取文本文件.我已经使用了一些目录的路径,但是什么也没有.
The compiler runs with no error, but i can not get the text file. I have used as well path to some of my directories and nothing.
知道发生了什么吗?谢谢
Any idea what's happening? Thanks
推荐答案
最后,我明白了!它通过更改以下几个参数来工作:
Finally I got it! It worked by changing few parameters like this:
var txtFile = "/tmp/test.txt";
var file = new File(txtFile,"write");
var str = JSON.stringify(JsonExport);
log("opening file...");
file.open();
log("writing file..");
file.writeline(str);
file.close();
不允许进入我的目录的路径,因此我不得不将其保存在/tmp目录中. 谢谢大家!
Path to my directories not allowed, so i had to save it on /tmp directory. Thanks to all!
这篇关于将Json对象导出到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!