JSON (JavaScriptObject Notation)-JS Object Notation is a strict subset of JavaScript. It is a development and text-based data exchange format, so JSON is not unique to JS, JSON can be parsed and serialized in many other languages.
Features:
1. Lightweight-easy to read and write, and easy to parse and generate
2. Data Types:
(1) simple values: String, value, Boolean value, and null. undefined in JS with special values is not supported.
(2) object
{
"User": "Admin ",
"Age": 25
}
(3) array
["Admin", 25, true]
Common formats
[
{
"User": "Admin ",
"Age": 25
},
{},{}
]
Analysis
Converts a JSON string to a JavaScript value.
var json = '[{"name" :"Admin","age" : 25},{"name" :"Forrest","age" : 24},{"name" :"LI","age" : 23}]';var jx =JSON.parse(json);
Optional parameter of the parse method: function (key, value) can be used to process key-value pairs.
Serialization
var array = [{name : "Admin",age : 25},{name : "Forrest",age : 24},{name : "LI",age : 23}];var json = JSON.stringify(array);alert(json);
Optional parameter of the stringify method: the first optional parameter is a function (complex processing) or array used to filter the results, and the second optional parameter is whether to retain indentation in JSON.
Summary
Currently, JSON is not substantially used for data processing. However, as a common data format, it is necessary to learn in advance and compare it with XML, JSON mainly reflects its lightweight advantages. We look forward to real application and in-depth development.