JS learning notes-JSON

Source: Internet
Author: User

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.