New features in Delphi 2009

Source: Internet
Author: User
Tags json

JSON (JavaScript Object notation) is similar to XML;

It started with JavaScript and was supported by multiple languages, and it became one of the new features of Delphi 2009.

If there is a section of XML: <id>2</id> <name> John </name> <age>99</age> with JSON can be expressed as: {"id": 2, "name": " John ", Age": 99}

JSON is extremely convenient to use in JavaScript, such as:

Example 1: Data = {"id":2, "name":"张三 ", "age":99};
str = Data.id;   //2
str = Data.name;  //张三
str = Data["name"]; //张三
//Example 2: Data = {"id":2, "name":{"FirstName":"张 ", "LastName":"三"}, "age":99};
str = Data.name.FirstName; //张
str = Data["name"]["FirstName"]; //张
//Example 3:/ Data =
[
 {"name":"张三", "age":9},
 {"name":"李四", "age":19},
 {"name":"王五", "age":29}
]
str = Data[2].name; //王五
str = Data[2]["name"]; //王五
/Example 4: The Data = {"name":"张三", "age":19, "like":["游戏","足球"]};
str = Data.like[1];  //足球
str = Data["like"][1]; //足球
JavaScript code in this example can also be debugged in Delphi, see:

Http://www.cnblogs.com/del/archive/2008/08/06/1261580.html

In JSON:

Elements and values are separated by a colon ":"

Elements and elements are separated by commas ","

{} is an object that can be nested in layers

[] represents an array, and the array elements are separated by commas ","

Values can be string, number, object, array, True, false, null; Where string to use double quotes (and language can be in single quotes)

You can use an escape character similar to the C language in string

Number can use the scientific counting method

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.