Skip to content Skip to sidebar Skip to footer

Setting An Array Of Objects To Sessionstorage

Ok, so I have this JSON: {'Status':'OK!','ListaPermessi': [{'IdPermesso':10,'Nome':'WIND_PARAMS'}, {'IdPermesso':11,'Nome':'ADMIN_SERVER'}, {'IdPermesso':21,'Nome':'REC'}, {'IdP

Solution 1:

You need to turn it back into a JSON string. You can do that with the JSON.stringify method:

sessionStorage.setItem("ListaPermessi", JSON.stringify(parsedResult.ListaPermessi));

The reason for this is that web storage can only store strings, and the default toString method of Object returns, as you've now seen, "[object Object]".


Side note: typeof is an operator, not a function, so there's no need for the parentheses:

if (typeof Storage !== "undefined") { //...

Post a Comment for "Setting An Array Of Objects To Sessionstorage"