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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JSON in JavaScript 
 

JSON stands for JavaScript Object Notation that is a language independent text format which is fast and easy to understand.

 

JSON in JavaScript

                         

JSON stands for JavaScript Object Notation that  is a language independent text format which is fast and easy to understand. That means it is really very simple and easy to learn without sparing much time. In another words we can say that JavaScript Object Notation is a lightweight data-interchange format that is completely language independent but with some conventions. 

So in this section of JSON tutorial we are going to discuss JSON  with JavaScript. 

Creating Object in JavaScript using JSON

We can create objects in JSON with JavaScript in many ways :

1. "var JSONObjectName ={};" will create an empty object. 

2. "var JSONObjectName= new Object();" will create a new Object.

3. "var JSONObjectName = { "name ":"amit", "age":23}; will create an Object with attribute name which contains value in String and age with numeric value.

Now by creating this object we can access attributes by only "." operator.

Here is the full example code for creating an Object in JavaScript using JSON:

ObjectJavaScript-JSON.htm

<html>
<head>
<title>
 Object creation in JSON in JavaScript
</title>
<script language="javascript" >
var JSONObject = {  "name"     "Amit",
                    "address"  "B-123 Bangalow",
                    "age"      23
                   "phone"     "011-4565763",
                   "MobileNo"  0981100092
          };
document.write("<h2><font color='blue'>Name</font>::"
    
+JSONObject.name+"</h2>");  
document.write("<h2><font color='blue'>Address</font>::"
    
+JSONObject.address+"</h2>");  
document.write("<h2><font color='blue'>Age</font>::"
    
+JSONObject.age+"</h2>");  
document.write("<h2><font color='blue'>Phone No.</font>::"
     +JSONObject.phone+
"</h2>");  
document.write("<h2><font color='blue'>Mobile No.</font>::"
    
+JSONObject.MobileNo+"</h2>");  
</script>
</head>
<body>
<h3>Example of object creation in JSON in JavaScript</h3>
</body>
</html>


Output:
  


To run this JavaScript and JSON example you have to just run this ".htm" file on your browser.


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 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

This is a good example.

I am a novice for javascript
I saw the above example. Here is an arrayList of JSONObject of javascipt but i want a similar arraylist which is from java class and use it in javascript similar to JSONObject.

If you have any idea please do help me.

Thanks in advance.

Posted by Sushant Gautam on Thursday, 12.11.08 @ 23:44pm | #82663

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.