2
A
回答
4
console.log(JSON.stringify([1,2,3,4,5]));
打开gedit或其他文本编辑器。从控制台复制。粘贴到文件中。保存为array.json。
编辑 Chrome支持copy
所以你可以做copy("foobar")
和“foobar的”就在你的剪贴板。
1
有一个jQuery插件jQuery.twFile,允许您读取和写入本地文件。
5
您可以使用数据URI方案的JSON转换为 “URL”,它可以然后下载,即
/* Firstly you'll need a javascript library which can encode data to base 64
* http://archive.plugins.jquery.com/project/base64 - jQuery Plugin
* http://www.webtoolkit.info/javascript-base64.html - Collection of functions
* http://stackoverflow.com/a/6740027/451672 - '' '' "
*/
/* Now we must convert the JSON to text, which can be done with the
JSON.stringify() method
* http://msdn.microsoft.com/en-us/library/cc836459(v=vs.85).aspx
*/
var data = JSON.stringify(myObject);
/* Now we convert the data to a Data URI Scheme, which must be Base64 encoded
make sure you use the appropriate method to Base64 encode your data depending
on the library you chose to use.
* application/octet-stream simply tells your browser to treat the URL as
arbitrary binary data, and won't try to display it in the browser window when
opened.
*/
var url = "data:application/octet-stream;base64," + Base64.encode(data);
/* To force the browser to download a file we need to use a custom method which
creates a hidden iframe, which allows browsers to download any given file
* http://stackoverflow.com/a/3749395/451672
*/
var downloadURL = function(url)
{
var iframe;
iframe = document.getElementById("hiddenDownloader");
if (iframe === null)
{
iframe = document.createElement('iframe');
iframe.id = "hiddenDownloader";
iframe.style.display = "none";
document.body.appendChild(iframe);
}
iframe.src = url;
}
/* Now downloading is simple as executing the following code, make sure that
the DOM is not modified until after the page has finished loading!
*/
window.onload = function()
{
var link = document.getElementById("downloadJSON");
link.onclick = function()
{
downloadURL(url);
}
}
的jsfiddle:http://jsfiddle.net/cQV7X/
相关问题
- 1. 将数据写入本地JSON文件
- 2. 写入JSON文件
- 3. 将俄文文本写入txt文件
- 4. 将文本写入文件的中间
- 5. 将文本文件的特定行写入文本文件 - Python
- 6. 将生成的JSON写入文件,BabyParse
- 7. Flume无法在HDFS上将Json文件写入Json文件
- 8. 将文本文件写入管道
- 9. 将LINQ结果写入文本文件
- 10. 将ArrayList写入文本文件
- 11. 将LinkedHashMap写入文本文件?
- 12. 将整数写入文本文件
- 13. MSI将TARGETDIR写入文本文件
- 14. 在Python中将文本写入文件
- 15. 将结果写入文本文件
- 16. Perl:将数组写入文本文件
- 17. 将一整行写入文本文件
- 18. 如何将文本写入XML文件?
- 19. 将Nokogiri输出写入文本文件
- 20. 将TEXTAREA内容写入文本文件
- 21. 无法将文本写入文件
- 22. 尝试将char []写入文本文件
- 23. 将输出写入文本文件
- 24. C++多次将文本写入文件
- 25. 将cout值写入文本文件
- 26. Java:将数组写入文本文件
- 27. 将JSON写入文件而无需将转义反斜杠写入文件?
- 28. 将对象写入json文件?
- 29. Python:将JSON字符串写入文件。
- 30. PYTHON如何将str输入文本写入文本文件