Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  161] [ 3]  / answers: 1 / hits: 65878  / 11 Years ago, sun, december 29, 2013, 12:00:00

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 (:


More From » jquery

 Answers
19

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'));

[#73503] Thursday, December 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darennevina

Total Points: 422
Total Questions: 128
Total Answers: 105

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
;