QT Development (61) Introduction to ———Json I. introduction of JSON
1. Introduction to JSON
JSON (JavaScript Object Notation) is a lightweight data interchange Format , based on JavaScript (standard ECMA-262 3rd Edition-december A subset of 1999). JSON uses a completely language-independent text format that uses the C-language family's habits (including C, C + +, C #, Java,JavaScript, Perl, Python, and so on).
JSON uses JavaScript syntax to describe data objects, but JSON is still independent of language and platform. The JSON parser and the JSON library support many different programming languages.
2. JSON Syntax
The JSON syntax is a subset of the JavaScript Object notation syntax , with the following syntax rules:
A, the data in the name /value pairs
B, data separated by commas
C, curly braces Save the object
D, square brackets Save Array
3.
JSON name / value pairs
The writing format for JSON data is: name/value pairs.
name /value pairs include the field name (in double quotation marks), followed by a colon, and then the value:
"FirstName": "John"
4.
JSON Value
JSON value type:
Number (integer or floating point)
String (in double quotes)
logical value (true or false)
Array (in square brackets)
Object (in curly braces)
Null
5.
JSON Object
The JSON object is written in curly braces:
An object can contain multiple name /value pairs:
{"FirstName": "John", "LastName": "Doe"}
6.
JSON Array
The JSON array is written in square brackets:
An array can contain multiple objects:
{"Employees": [{"FirstName": "John", "LastName": "Doe"}, {"FirstName": "Anna", "LastName": "Smith"}, {"Firstn Ame ":" Peter "," LastName ":" Jones "}]}
ii. JSON Infrastructure
There are two types of structures in the JSON structure : objects and arrays.
1.
Object
The object is represented as "{}" and the data structure is {Key:value,key:value,...} The structure of the key-value pairs . In an object-oriented language,key is a property of an object, value is the corresponding property value, and the property value method is: Object . Key, the type of the property value can be a number, a string, an array, an object.
{"FirstName": "Brett"}
{"FirstName": "Brett", "LastName": "McLaughlin", "email": "[email protected]"}
When multiple name/value pairs are strung together, JSON is easier to use and more readable. When more than one name/value pair explicitly indicates that multiple values are part of the same record, curly braces make some kind of connection between multiple values.
2.
Array
The array is represented by brackets "[]", the data structure is ["Java", "JavaScript", "VB",...], the value is obtained using index, the type of the field value can be a number, a string, an array, an object.
When you need to represent a set of values, JSON not only improves readability, but also reduces complexity.
A variable of a single value (with multiple records) is as follows:
{"People": [{"FirstName": "Brett", "LastName": "McLaughlin", "email": "AAAA"}, {"FirstName": "Jason", "LastName ":" Hunter "," email ":" BBBB "}, {" FirstName ":" Elliotte "," LastName ":" Harold "," email ":" CCCC "}]}
People variable, the value is an array of three entries, each of which is a person's record, which contains the first name, last name, and e-mail address.
Variables with multiple values (each containing multiple records) are as follows:
{ "Programmers": [ { "FirstName": "Brett", "LastName": "McLaughlin", "email": "AAAA" }, { "FirstName": "Jason", "LastName": "Hunter", "email": "BBBB" }, { "FirstName": "Elliotte", "LastName": "Harold", "email": "CCCC" }], "Authors": [ { "FirstName": "ISAAC", "LastName": "Asimov", "genre": "Sciencefiction" }, { "FirstName": "Tad", "LastName": "Williams", "Genre": "Fantasy " }, { "FirstName": "Frank", "LastName": "Peretti", "Genre": " Christianfiction " }], "Musicians": [ { "FirstName": "Eric", "LastName": "Clapton", " Instrument ": " Guitar " }, { "FirstName": "Sergei", "LastName": "Rachmaninoff", "Instrument": "Piano"         }]}
This article from "Life is endless, struggle not only" blog, declined reprint!
QT Development (61) Introduction to ——— JSON