JSON (Javescript Object Notation) is a simple data format that is lighter than XML. JSON is a native JavaScript format, which means that working with JSON data in JavaScript does not require any special APIs or toolkits.
The rules of JSON are simple: an object is an unordered collection of "name/value pairs". An object starts with "{" (opening parenthesis) and "}" (the closing parenthesis) ends. Each "name" followed by a ":" (colon); "' Name/value ' pair", "(comma) delimited
To give a simple example:
JS Code
function Showjson () { var user = { "username": "Andy", "age": +, "info": {"tel": " 13564254568 "," cellphone ":" 6526975 "}, " address ": [ {" City ":" Shanghai "," postcode ":" 111222 "},
{"City": "NewYork", "Postcode": "333444"} ] } alert (user.username); alert (user.age); alert (User.info.cellphone); alert (user.address[0].city); alert (User.address[0].postcode); }
This represents a user object that has attributes such as username, age, info, address, and so on.
You can also use JSON to simply modify the data, modify the above example
JS Code
function Showjson () { var user = {
"username": "Andy", "age": +, "info": {"tel": "13564254568", "cellphone": "6526975"}, "Address": [ {"City": "Shanghai", "postcode": "111222"}, {"City": "NewYork", "Postcode": "333444"} ]
}
alert (user.username); }
How JavaScript handles JSON data