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