Skip to content

Instantly share code, notes, and snippets.

@ariesmcrae
Created July 9, 2014 06:19
Show Gist options
  • Save ariesmcrae/783151620628c225c0b4 to your computer and use it in GitHub Desktop.
Save ariesmcrae/783151620628c225c0b4 to your computer and use it in GitHub Desktop.
Javascript that reads an embedded JSON
<!doctype html>
<html>
<head>
<script>
function displayJSON() {
var scheduler = [
{"id": 7, "name": "Abc", "isOn": false, "count": 5, "date": "2014-01-05"},
{"id": 3, "name": "Gringo", "isOn": false, "count": 97, "date": "2017-09-21"},
{"id": 99, "name": "Schedule 1", "isOn": true, "count": 432, "date": "2013-12-16"},
{"id": 12, "name": "lol", "isOn": false, "count": 56, "date": "2014-10-13"}
]
var myDiv = document.getElementById('MyDiv');
var str = '';
for (var i = 0; i < scheduler.length; i++) {
str += 'id=' + scheduler[i].id + ' '
+ 'name=' + scheduler[i].name + ' '
+ 'isOn=' + scheduler[i].isOn + ' '
+ 'count=' + scheduler[i].count + ' '
+ 'date=' + scheduler[i].date + '<br/><br/>';
}
myDiv.innerHTML = str;
}
</script>
<style>
div { font-family: courier; }
</style>
</head>
<body onload="displayJSON()">
<div id="MyDiv" />
<body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment