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 JavaScriptObject Notationthat 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 JavaScriptObject Notation is a lightweight data-interchangeformat that iscompletely language independent but with some conventions.
So in thissection 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 manyways :
1. "var JSONObjectName ={};" willcreate an empty object.
2. "var JSONObjectName= new Object();"will create a new Object.
3. "var JSONObjectName = { "name":"amit", "age":23}; will create an Object withattribute name which contains value in String and age with numericvalue.
Now by creating this object we can access attributes byonly "." operator.
Here is the full example code for creating an Object inJavaScript 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>
Categories: JavaScript, JQUERY, Personal
Post a Comment
Oops!
The words you entered did not match the given text. Please try again.
Oops!
Oops, you forgot something.