The creation of JavaScript objects is defined using JSON format

Source: Internet
Author: User

Json:javascript Simple Object notation.

JSON is the object of JS, but it omits the tags in the XML, but instead uses the {} to complete the description of the object.

Defining objects

var person = {    // by property Name: property value to indicate, different attributes passed, to interval    age:25,      function() {        alert (this, age);    } // the last property cannot be followed by a }person.say ();

Defining an Ordinary array

You can still create an array of objects through JSON, just as you would create an array of JS.

var array = [    {name:"Zs", Age:24},        {name:"ls", age:25}];          for (var i=0; i<array.length; i++) {    alert (array[i].name);}

Defining an array of objects

Create a group of users with a property of name, age, friends

Person.java:name:string, Age:int, Friends:array

list<person> PS = new arraylist<person> ();

Ps.add (New person ("Leon", 22,["Ada", "Alice"]));

Ps.add (New person ("John", 33,["Ada", "Chris"]));

var persons = [    {        "Leon",                  friends:["Ada", "Alice"]    },    {        "John",                  friends:[,"Ada", "Chris"]    }     for (var i=0; i<persons.length; i++) {    +--+ + Persons[i].age + "-- > "+ persons[i].friends);}

The creation of JavaScript objects is defined using JSON format

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.