How JavaScript handles JSON data

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.