RobertJay
Posts: 0
Joined: Fri Jun 15, 2012 1:32 pm

Displaying JSON object from local storage in Alert window

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Displaying JSON object from local storage in Alert window

Hi Robert,

How do you do this?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Displaying JSON object from local storage in Alert window

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

RobertJay
Posts: 0
Joined: Fri Jun 15, 2012 1:32 pm

Displaying JSON object from local storage in Alert window

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?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Displaying JSON object from local storage in Alert window

Hello Robert,

On service response variables will be stored in local storage in string format automatically.

Return to “Issues”