Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write data into a JSON file using jquery [closed]

Am making an hybrid mobile app and i need to store some of the data like for example if its a game : the high score etc .. so far am able to read data from JSON file using jquery .., but is it possible to write to JSON file ??!

Or is there any other way to do so ?

IDE - Eclipse ( plugin - IBM worklight studio )

Only HTML 5 and JS and JQ can be used !

Thanks (:

like image 522
Dhayalan Pro Avatar asked Dec 29 '13 08:12

Dhayalan Pro


Video Answer


1 Answers

You can write JSON into local storage and just use JSON.stringify (non-jQuery) to serialize a JavaScript object. You cannot write to any file using JavaScript alone. Just cookies or local (or session) storage.

var obj = {
    name: 'Dhayalan',
    score: 100
};

localStorage.setItem('gameStorage', JSON.stringify(obj));

And to retrieve the object later, such as on page refresh or browser close/open...

var obj = JSON.parse(localStorage.getItem('gameStorage'));
like image 87
Jesse Avatar answered Sep 19 '22 13:09

Jesse