Question

use a JSON data structure which contains student information (StudentId, FName, LName, Address, City, State, Zip,...

use a JSON data structure which contains student information (StudentId, FName, LName, Address, City, State, Zip, E-mail, Phone, Major, AdvisorName, AdvisorEmail).

Using the Foreach statement display all the contents of the JSON data structure into a webpage.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the answer for your question using HTML and JavaScript(JSON) Languages.

NOTE : datatstructure.js file contains the JSON datastructure and data.html will display the data in datastructure.js.

Please see the comments in each line for better understanding

CODE :

datastructure.js

//JSON data structure is a collection of objects
//It consists of name : value pairs
//Names should be in double quotes
//Values with string values should be in double quotes and numbers
//can be specified without quotes
//{ } braces contains collection of name : value pairs i.e., objects
var datastructure = {
           "StudentId" : 1234,
           "FName" : "John",
           "LName" : "Doe",
           "Address" : "Street No.1 Lane 23 Fold",
           "City" : "Cumerics",
           "State" : "Washington",
           "Zip" : 12345,
           "Email" : "[email protected]",
           "phone" : 123456789,
           "Major" : "abcd",
           "AdvisorName" : "Holmes",
           "AdvisorEmail" : "[email protected]" }

data.html

<!DOCTYPE html>
<html>
<head>
<title>JSON Datastructure</title>
<!--Linking datastructure.js file -->
<script src="datastructure.js"></script>
</head>
<body>
   <h1>Data Taken from JSON Data Structure</h1>
<h3 id="result"></h3>
<script>
//Displaying the data in html element
//Getting a html element via its ID
var result = document.getElementById("result");
//Displaying data
//Looping through each object in the datastructure
//Displaying name and values
for( i in datastructure){
   result.innerHTML += i + " : " + datastructure[i] + "<br/>";
}
</script>
</body>
</html>

SCREENSHOTS :

Please see the screenshots of the code for the indentations of the code.

(datastructure.js)

(data.html)

OUTPUT :

Any doubts regarding this can be explained with pleasure :)

Add a comment
Know the answer?
Add Answer to:
use a JSON data structure which contains student information (StudentId, FName, LName, Address, City, State, Zip,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT