
How do i fetch string values from client side and then parse it using JSON

The given code parse the message in JSON in JavaScript. You can parse the message with JSON in JavaScript by using the method "String.parseJSON(filter)". It parses the JSON message to an string or object. The parameter "filter" is optional in this method which is used to filter message or transform their results. This method internally uses the JavaScript's method eval() to parse messages.
<html>
<head>
<title>Parsing Message using JSON in JavaScript</title>
<script language="javascript" src="json2.js"></script>
<script language="javascript" >
var students = {
"Maths" : [
{ "Name" : "Amit", // First element
"Marks" : 67,
"age" : 23 },
{
"Name" : "Sandeep", // Second element
"Marks" : 65,
"age" : 21 }
]
}
// Printing Maths array values in the alert message
var i=0
var arrayObject = new Array();
for(i=0;i<students.Maths.length;i++)
{
arrayObject.push(students.Maths[i].Name);
arrayObject.push(students.Maths[i].Marks);
arrayObject.push(students.Maths[i].age);
}
alert("Parsing JSON Message Example ");
alert(arrayObject.toJSONString().parseJSON());
</script>
</head>
<body>
Parsing Message using JSON in JavaScript
</body>
</html>
For more information, visit the following link:
http://www.roseindia.net/tutorials/json/creating-message-json.shtml
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.