Skip to content Skip to footer

Storing JSON Objects in HTML5 Local Storage

4 Comments

  • Praveen Saxena
    Posted Mar 20, 2013 at 9:02 pm

    nice article! but when i am using JSON.Parse(person). it throws an error saying invalid character. I could not figure out what was that. here is my code.

    $(document).ready(function () {

    if (typeof (Storage) != “undefined”) {

    var emp = {Name: “Chris”, Age: 30, IsPermanent: true };

    localStorage.setItem(“employee”, emp);

    }

    else { alert(“sorry your browser does not support web storage.”); }

    $(“#btnGetEmp”).click(function () {

    if (typeof (Storage) != “undefined”) {

    var emp = localStorage.getItem(“employee”);

    //alert(typeof (emp)); // string

    var emps = JSON.parse(emp); // throws an error 0x800a03f6 – JavaScript runtime error: Invalid character

    }

    else { alert(“sorry your browser does not support web storage.”); }

    });

    });

  • Trackback: Blog Post from the Week (17th - 30th March 2013) - The South Asia MVP Blog - Site Home - TechNet Blogs
  • Ganesh YN
    Posted Jun 11, 2013 at 5:20 pm

    can you try JSON.parse(emp.employee);

  • Shravan Kumar Kasagoni
    Posted Jun 12, 2013 at 10:44 pm

    use

    emp = JSON.stringify(emp); before storing in local storage

Leave a comment

0/100