Saturday, March 1, 2014

JSON: JavaScript Object Notation.




Similar to XML, JSON is used to store message in JavaScript.   But JSON is smaller than XML and easy to parse.
JSON format:
a name followed by colon, followed by a value, such as
"fruit":"apple"
i.e fruit = "apple"
JSON object using curly bracket
var  temp={"fruit":"apple", "juice":"orange"}
To access JSON object value:
temp.fruit, temp,juice
JSON array using square bracket:
var JSONarray= {
"food":[
{"fruit":"apple", "juice":"orange"},
{"fruit":"banana", "juice":"watermelon"}
]
}

To access the value  fruit in array
JSONarray.food[0].fruit

No comments:

Post a Comment