Storing an object in localStorage can sometimes lead to unexpected errors. Take this example:
function onExit(){
localStorage.setItem("my_object","'" + JSON.stringify(object) + "'");
}
When retrieving this data from localStorage, it may look like this:
'{"date":"2016-05-31T23:00:00.000Z","Name":"name","Code":"code","required":"false"}'
Interestingly, calling JSON.parse directly on the object works fine:
JSON.parse('{"date":"2016-05-31T23:00:00.000Z","Name":"name","Code":"code","required":"false"}')
However, trying to parse the object stored in localStorage throws an error:
JSON.parse(localStorage.my_object)
This results in an 'unexpected character at line 1 of JSON data' message. The issue could be related to how the object is being stored or retrieved. It may be worth exploring different methods to resolve this problem.