How to read and write JSON locally in Cordova?

Asked

Viewed 1,289 times

1

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

I thought I’d create a JSON in the application root folder to load the data on APP startup.

Even for sure, but, how to do the reverse?

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

I saw that you can do using localStorage, but that way the data gets lost when closing the application.

1 answer

1


Consulting the link to Storage of 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 file API.

In your case how you intend to use JSON recommend the use of a plugin for file manipulation. In this case you open the file JSON from memory, works with it and at some point records it again to memory.

I myself worked on a project with file storage in memory, so 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.