(This is for local use only, using WAMP) I have some Javascript's that create a array containing some string and objects. I would like to save this array to a file, so that i can later load it into another JavaScript.
I have seached Google all night, but can seem to find any way of doing this :(
use JSON.stringify(myarray)
first, then you can use AJAX to send the data to the server. You can use file_put_contents
(php) to save the file to the server's disk...you can retrieve the array and use it later using JSON.parse(array_from_file);
您可以将json发送到php服务器,然后从那里将其写入json文件。
If you are doing this locally, you can constrain yourself to Chrome and use the HTML5 FileWriter API. Here's a guide to get you started. Also, you can check on the status of the browser compatibility matrix here .
Also, you might want to consider using the HTML5 LocalStorage or SessionStorage API's as well.
There's also the HTML5 FileSystem API polyfill that uses IndexedDB .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.