How can I deserialize JSON {name, value} in C#?

Trouble with JSON Data taken from localStorage in JavaScript/HTML5?

  • I am making a completely offline HTML5 web app. In a particular part of my code, I am required to add a row of data to a JavaScript Array Object and save the updated version back to localStorage. Here is the code: var data = localStorage.getItem("cars"); data.goals.push(["name": "merscede", "model": "bmw", "noofdays": "10", "active": "yes"]); //Trouble in this line. localStorage.setItem("goals",data); And this is the value I had stored in the localStorage in a different part of the source code: var data = '{"goals":[{"name":"rocky","model":"old","noofdays":"50","active":"no"}]}'; localStorage.setItem("goals",data); I have trobleshooted extensively and it turns out that only the senctence that I have particularly marked has all the trouble. What's the problem? What should I do?

  • Answer:

    Here is the working version: var data = {"goals":[{"name":"rocky","model":"old","noofdays":"50","active":"no"}]}; localStorage.setItem("goals",JSON.stringify(data)); data = JSON.parse(localStorage.getItem("goals")); console.log(data); data.goals.push({"name": "merscede", "model": "bmw", "noofdays": "10", "active": "yes"}); localStorage.setItem("goals",JSON.stringify(data)); data = JSON.parse(localStorage.getItem("goals")); console.log(data);

Ranjan Kumar at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.