I am struggling with modifying my local storage and it's taking up a lot of my time.
Initially, I set it up like this:
localStorage.setItem('example','{"data": []}');
It was working fine, but now I need to structure it like the following example:
{
"data" : [
{
"id" : "0",
"name" : "Alice",
"type" : "A",
"value" : "1",
"created_at" : "2012-09-23 08:00:00"
},
{
"id" : "1",
"name" : "Bob",
"type" : "B",
"value" : "5",
"created_at" : "2012-09-23 10:00:00"
}
],
"index" : 0
}
So, I tried this:
localStorage.setItem('example','{"data":[]},{"index":0}');
But now I keep getting the error message:
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data
[Break On This Error]
var objJSON = JSON.parse(localStorage.getItem('example'));
Can someone help me understand how to correctly initialize my local storage? Thanks.