JSON in 5 seconds

<script type=”text/javascript”>

/*sample code by stikiflem

Copy and Paste all of these. Save as sample.html. Run in browser.
*/
function getData(){

var sampleJSON = {
// string
a : ‘accessing a string in json’,
// array
b : ['obj1','im a string in an array!','three',4,'obj5'],
// function
c : function() {
alert(‘im a function!’);
}
}

alert(sampleJSON.a);
alert(sampleJSON.b[1]);
alert(sampleJSON.c());

}
/*
JSON is just pure javascript. no BS.
Just remember:
1. Entry inside {} are properties.
2. Entry with [] is an array which can contain another array or a property.
3. JSON can also carry a function (e.g. in alert #3)
*/
</script>
<input type=”button” value=”Get JSON Sample” onClick=”getData();” />

2 Responses to “JSON in 5 seconds”

  1. Thanks for the info (and for Struts2JSON)

    You may want to convert those single and double quotes as a simple cut and paste is not so simple.

  2. Its an excellent for beginners, try to give some more example like this, so fresher can able understand easily.

Leave a Reply