I'm new to using JSON and I'm trying to do something that I'm convinced is very simple but I've been looking for a while and haven't yet found the right way to do it. I have two files, a html page and a json file with an array inside it. The contents of the JSON file looks like this:
[
{ "name": "EXAMPLE1",
"description": "this is a sample description"},
{ "name": "EXAMPLE2",
"description": "This is a second sample description"}
]
What I'm trying to do fetch the array elements and display them on the html page with "name" being a heading (h1) and "description" being a paragraph (p).
Below is the code I have so far in my html file and I wouldn't be surprised if I've totally misunderstood how to go about this:
<!DOCTYPE html>
<html>
<head>
<title>Json Arrays</title>
</head>
<body>
</body>
<script>
$(document).ready(function(){
$.getJSON("testarray.json", function(data){
$.each(data, function)(){
$("body").append("<h1>"+this['name']+<br>"</h1>""<p>"+this['description']+<br>"</p>");
}
}
}
</script>
</html>
Any suggestions would be very appreciated.