Page 1 of 1
Displaying JSON object from local storage in Alert window
Posted: Fri May 09, 2014 7:58 pm
by RobertJay
This is not a big deal, but I was wondering how a JSON object being stored in local storage can be viewed in an alert box. When I display it, there is nothing which shows other than a bottom scroll bar as shown below. String values display fine. Thanks.
http://screencast.com/t/ZSZVm60zF
Displaying JSON object from local storage in Alert window
Posted: Fri May 09, 2014 8:58 pm
by Kateryna Grynko
Hi Robert,
How do you do this?
Displaying JSON object from local storage in Alert window
Posted: Fri May 09, 2014 9:13 pm
by RobertJay
Displaying JSON object from local storage in Alert window
Posted: Mon May 12, 2014 11:41 am
by Kateryna Grynko
Hi Robert,
LocalStorage Name/value pairs are always stored as strings.
If you write correct JSON string in localStorage, you won't have any problem.
Try this simple test for working with locaStorage:
prevar obj = {x: 5, y: 6};
var s = JSON.stringify(obj);
localStorage.setItem("test",s);
var r = localStorage.getItem("test");
alert(r);/pre
Displaying JSON object from local storage in Alert window
Posted: Mon May 12, 2014 12:16 pm
by RobertJay
Thanks Katya. I guess I was storing the pure object and not the string version. Question: on a service response will the variable be stored automatically in string format or do I have to do the stringify first?
Displaying JSON object from local storage in Alert window
Posted: Mon May 12, 2014 8:21 pm
by Evgene Karachevtsev
Hello Robert,
On service response variables will be stored in local storage in string format automatically.