JSON : JavaScript Ojbect Notation.
It contains name/value pairs, array and other object for passing aroung ojbect in java script. It is subset of JavaScript and can be used as object in javascript.
You can use JSON to store name/value pair and array of ojbect.
It has eval() method to assign value to variable.
In below example, I have put all things together.
Just make one html file and you can start your practice on it.
How to use this tutorial:
1. Make one file JSONDemo.html
2. And paste below code
<html>
<head>
<body>
<script language="javascript">
eval("var amount =10;");
alert("Value of amount :: "+amount);
var student = {
name : "Binod",
roll : 110,
subject : ["Java","Database","Networking"]
}
alert("Student Name :: "+student.name);
alert("Student All Subject :: "+student.subject);
alert("Student First Subject :: "+student.subject[0]);
alert("Student No. of Subject :: "+student.subject.length);
for(var i=0;i<student.subject.length;i++){
var value = student.subject[i];
alert(value);
}
var person = {
name : "Ambani",
books : [
{
title : "Java Programming",
author : "Binod Suman"
},
{
title : "XML",
author : "Don Box"
}
]
}
alert("Book Title :: "+person.books[0].title);
alert("Book Author :: "+person.books[0].author);
</script>
Please put your comment on this post for enhance this blog or this tutorial.
Thanks and have a nice day ............ :)
Sunday, May 24, 2009
Subscribe to:
Post Comments (Atom)
It's nice example.But my question is that why we use JSONObject and JSONArray instead of Map interface.
ReplyDeleteWe can use JSON object in javascript as there is no native support for Maps inteface within Javascript. You can visit this link
ReplyDeletehttp://www.coderanch.com/t/289271/JSP/java/javascript-HashMap
- Parag MPS US
json is a very interesting language to be used. very good tutorial and can hopefully help me in building json in the application that I created for this lecture. thank you
ReplyDeleteI tried this but not working..............why?
ReplyDeleteIts been seen a lack of explanation in the example.
ReplyDeleteplease provide few standard example which is used around the IT industries and please dont copy paste from other web site.