Jvascript Learning Notes---JSON data format

Source: Internet
Author: User

JSON (Javascriptobject 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 ends with "{" Starting with "}". Each "name" is followed by a ":" (colon); "' Name/value ' pair ' is separated by", "(comma).

A simple example:

var user =

{

"username": "Andy",

"Age": 20,

"Info": {"tel": "123456", "cellphone": "98765"},

"Address":

[

{"City": "Beijing", "postcode": "222333"},

{"City": "NewYork", "Postcode": "555666"}

]

}

alert (user.username);

alert (user.age);

alert (User.info.cellphone);

alert (user.address[0].city);

alert (User.address[0].postcode);

String to JSON data object:

var user = ' {' username ': ' Andy '} ';
var obj = eval (' (' +user+ ') ');
alert (obj.username);

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.