How to read and write JSON locally in Cordova?

1

I need a simple solution to persistently load and update data in a mobile APP using Cordova.

I thought about creating a JSON in the root folder of the application to load the data at APP initialization.

All right, but how to do the reverse?

For example: the script loads the JSON and plays in View > the user modifies this data in some way > the stringify() script and stores the updated JSON back into the root folder. I think you can not do this with POST .

I saw what you can do using localStorage , but this way the data gets lost when you close the application.

    
asked by anonymous 11.02.2015 / 07:07

1 answer

1

By checking the Storage link in the documentation we can see that there are several methods , such as:

  • localStorage
  • WebSQL
  • IndexedDB
  • Or use some plugin to do specific storage as the files API.

In your case as you intend to use JSON recommend the use of a plugin for file manipulation. In this case you open the file JSON from memory, work with it and at some point write it back to memory.

I even worked on a project with file storage in memory, for that I used a plugin called Cordova Simple File Management , with it the file management process becomes much easier than having to create functions to access the File API.

    
11.02.2015 / 12:28