|
<html>
<head>
<title>
JSON Message Parsing With Example
</title>
<script language="javascript" src="json2.js"></script>
<script language="javascript" >
var StudentsDetails = {
////Decalration of array to collect record of Student.
// Information of MCA students
"MCAStudent": [{
"StudentName": "Kumar Vishu",
"Roll_No":100,
"Stream": "Computer Science",
"Course": "MCA"
},
{
"StudentName": "Tarun Bindra",
"Roll_No":101,
"Stream": "Science",
"Course": "B.Tech"
}
]
}
// Printing all array values
var i=0
var dataCollection = new Array();
for(i=0;i<StudentsDetails.MCAStudent.length;i++)
{
// Push the data into array
dataCollection.push(StudentsDetails.MCAStudent[i].StudentName);
dataCollection.push(StudentsDetails.MCAStudent[i].Roll_No);
dataCollection.push(StudentsDetails.MCAStudent[i].Stream);
dataCollection.push(StudentsDetails.MCAStudent[i].Course);
}
alert("Welcome to JSON Message Example ");
// Use toJSONString() function for message parsing
alert(dataCollection.toJSONString());
</script>
</head>
<body>
Message parsing successfully in JavaScript using JSON.
</body>
</html>
|