More Tutorials| Bioinformatics| Open Source| Photoshop| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Parsing a message in JavaScript with JSON 
 

In the previous section of example we have studied how to create message in JSON in JavaScript and now we will come to know that how we can parse the message in JSON in JavaScript.

 

Parsing a message in JavaScript with JSON

                         

In the previous section of example we have studied how to create message in JSON in JavaScript and now we will come to know that how we can parse the message in JSON in JavaScript.

We 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.

Here is the full example code for ParseMessageJSON.htm as follows:

 

 

ParseMessageJSON.htm

<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>

To run this example we need to have json2.js file included with our ParseMessageJSON.htm file. File "json2.js" is as same as in our previous example of "creating message in JavaScript with JSON" .

Output:

Run ParseMessageJSON.htm file on your browser. It will generate output on your browser as follows:




Download Code

 

                         

» View all related tutorials
Related Tags: java c json class io classes servlet vi using this create js for example to learn exam sse ear e

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.