What is Json?
JSON (JavaScript Object Notation) is a lightweight data exchange format. It is based on a subset of JavaScript (Standard ECMA-262 3rd Edition - December 1999). JSON adopts
a completely language-independent text format, but also uses conventions similar to the C language family (including C, C, C#, Java, JavaScript, Perl, Python, etc.). These properties make JSON an ideal data exchange language. Easy for humans to read and write, and easy for machines to parse and generate.
JSON has two structures:
Json is simply an object and an array in JavaScript, so these two structures are objects and arrays. Various complex structures can be expressed through these two structures
1. Object: The object is represented in js as the content expanded by "{}", and the data structure is the key-value pair structure of {key: value, key: value,...}. In object-oriented language, Key is the attribute of the object, and value is the corresponding attribute value, so it is easy to understand. The value method is object.key to obtain the attribute value. The type of this attribute value can be numbers, strings, arrays, and objects.
2. Array: Array in js is the content expanded by square brackets "[]". The data structure is ["java", "javascript", "vb",...], and the value method is the same as in all languages. Same as in, using index to obtain, the type of field value can be number, string, array, object.
Complex data structures can be combined through the two structures of objects and arrays.
The format or rules of JSON:
JSON can describe the data structure in a very simple way. It can do everything XML can do, so the two are completely equal in terms of cross-platform.
1. JSON has only two data type descriptors, curly brackets {} and square brackets []. The remaining English colons are mapping characters, English commas are delimiters, and English double quotes "" are defining characters.
2. Curly brackets {} are used to describe a set of "different types of unordered key-value pair sets" (each key-value pair can be understood as an OOP attribute description), and square brackets [] are used to describe a set of " "Ordered data collection of the same type" (which can correspond to OOP arrays).
3. If there are multiple sub-items in the above two sets, they should be separated by commas.
4. The key-value pairs are separated by English colon:, and it is recommended that the key names be added with English double quotes "" to facilitate the analysis of different languages.
5. Commonly used data types within JSON are nothing more than strings, numbers, Boolean, dates, and null. Strings must be enclosed in double quotes, and the rest are not used. The date type is quite special, so I won’t go into detail here. Yes, I just suggest that if the client does not have the function of sorting by date, then just pass the date and time directly as a string, which can save a lot of trouble.
JSON example