Articles → Jquery → Read JSON Data Using Jquery
Read JSON Data Using Jquery
Software Requirement
- Any text editor like notepad is there on your machine.
- Any browser like I.E, chrome etc is installed on your machine.
- JQuery file (1.7.2) uncompressed downloaded from http://jquery.com/download/
Prerequisite Knowledge
- Basics about HTML
- Basics about JQuery
- Basics about JSON.
Steps Of Execution
- Create a new HTML file and add span tags in it.
- Add JavaScript code to access JSON
Create A New HTML File And Add Span Tags In It
<body>
<h2>Reading student information from json data</h2>
Name:
<span id="nameperson"></span>
<br />
Age:
<span id="ageperson"></span>
<br />
Technology:
<span id="technologyspan"></span>
<br />
Address:
<span id="addressspan"></span>
<br />
</body>
Add Javascript Code To Access JSON
<script src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var Trainer = {
"Name": "Karan Gupta",
"Age": 28,
"Technology": "JSON",
"Address": {
"City": "Gurgaon",
"State": "Haryana"
}
};
document.getElementById("nameperson").innerHTML = Trainer.Name;
document.getElementById("ageperson").innerHTML = Trainer.Age;
document.getElementById("technologyspan").innerHTML = Trainer.Technology;
document.getElementById("addressspan").innerHTML = Trainer.Address.City;
});
</script>
Output
Click to Enlarge