As a beginner in learning JSON, I find that W3schools does not provide clear explanations of what each line of code does. While I can interpret some parts, there are sections that still remain unclear to me.
// Data storage process:
1. myObj = {name: "John", age: 31, city: "New York"};
2. myJSON = JSON.stringify(myObj);
3. localStorage.setItem("testJSON", myJSON);
// Retrieving stored data:
4. text = localStorage.getItem("testJSON");
5. obj = JSON.parse(text);
6. document.getElementById("demo").innerHTML = obj.name;
I understand the purpose of line one, which is basically creating variables for storage. Line two seems straightforward as it converts variable storage into a string format. However, line three's operation is not entirely clear to me and I would appreciate an explanation.
Lines four and five also pose some confusion for me. On the other hand, line six is much easier to comprehend.
To summarize, I would like clarification on lines 2, 3, 4, and 5 functionality.