JS JSON


JSON is the abbreviation of JavaScript Object Notation. It's an important data format for exchange over the internet.


JSON structure is an array of key - value pairs.

var jn = {"Bangalore":"India","New York":"USA"};


"." or "[]" can be used to Access JSON values.

alert(jn.Bangalore); //India
alert(jn["New York"]); //USA


There is a JS package json.js located at https://github.com/douglascrockford/JSon-js/ which provides several methods for JSON parsing.

<script language=javascript src="/your directory/json.js"></script>

<script language=javascript>
var str='{"Bangalore":"India","New York":"USA"}';
var obj=str.parseJSON();
alert(obj.toJSONString()); //{"Bangalore":"India","New York":"USA"}
alert(obj.Bangalore); //India
</script>


JSON is widely used in AJAX applications.


endmemo.com © 2024  | Terms of Use | Privacy | Home