1. Two array structures in JSON:
- Object structure: The object structure is expressed as the content enclosed by { } in JSON. The data structure is a key-value pair structure of { key: value, key: value, … }. Among them, the key must be a string wrapped in English double quotes, and the data type of value can be number, string, Boolean, null, array, and object.
- Array structure: The array structure is expressed as the content enclosed by [] in JSON. The data structure is [ "java", "javascript", 30, true ...]. The data types in the array can be numbers, strings, Boolean values, null, arrays, and objects.
2. Notes on JSON syntax:
- Attribute names must be wrapped in double quotes
- Values of type string must be wrapped in double quotes
- Single quotes for strings are not allowed in JSON
- Comments cannot be written in JSON
- The outermost layer of JSON must be in object or array format
- Cannot use undefined or functions as JSON values
What JSON does: Store and transfer data between computers and networks.
3. The relationship between JSON and js objects
- JSON is a string representation of JS objects, which uses text to represent the information of a JS object, essentially a string. For example:
This is an object
var obj = {a:'Hello', b: ' World' }
This is a JSON string, essentially a string
var json = '{"a": "Hello", "b": "World"}'
4. Mutual conversion between JSON and js objects
- To convert from a JSON string to a JS object, use the JSON.parse() method:
var obj = JSON.parse(' {"a": "Hello", "b": "World"} ')
turn out
{a: 'Hello', b: 'World'}
- To convert from a JS object to a JSON string, use
JSON.stringify()
the method:
var json = JSON. stringify({a 'Hello', b: 'World'})
turn out
' {"a": "Hello", "b": "World"} '
5. Deserialization and deserialization of JSON
- The process of converting data objects into strings is called serialization, for example, the operation of calling the JSON.stringify0 function is called JSON serialization.
- The process of converting a string into a data object is called deserialization. For example, the operation of calling the JSON.parse0 function is called JSON deserialization.