My JSON data is as follows:
[
{
"0": "324",
"1": "Cavill ",
"2": "11",
"3": "100018463",
"4": "RAR",
"5": "DummyX",
"6": "DummyY",
"7": "Moretext",
"8": "moretext",
"id": "lol",
"teacher": "Specsavers ",
"rate": "11",
"teacherid": "100018463",
"address": "114 Road X",
"postcode": "WXER 21",
"lat": "51.511871",
"lon": "-0.112934",
"distance": "0.023308985382378217"
}
]
This data is stored in a variable named "hold".
I am attempting to display the "teacher" value within a div labeled output1.
The code I'm using is shown below:
obj = JSON.parse(hold);
document.getElementById("output1").innerHTML = obj[1].teacher;
However, I keep receiving an undefined result.
I've also tried changing index from 1 to 0 but encountered the same issue - still undefined.
Can you help me identify what might be causing this problem?
How can I correctly access attribute data from each node or branch of the JSON? Thank you!