Java EE Development Technology Course Week seventh (JSON)

Source: Internet
Author: User

Json:

Https://baike.baidu.com/item/JSON/2462549?fr=aladdin

JSON refers to JavaScript Object notation (JavaScript object Notation), which is a lightweight data interchange format that stores and represents data in a text format that is completely independent of the programming language, effectively improving network transmission efficiency.

JSON syntax JSON syntax rules in the JS language, everything is an object. Therefore, any supported type can be represented by JSON, such as strings, numbers, objects, arrays, and so on. However, objects and arrays are two of the more special and common types:
    • object is represented as a key-value pair
    • Data is separated by commas
    • Curly braces Save Object
    • Square brackets Save Array
JSON key/value pairs JSON key-value pairs are used to save the JS object of a way, and JS object notation is similar, key/value pairs in the combination of key names written in front and double quotation marks "" package, using a colon: delimited, and then the value:
1 {"firstName": "Json"}
This is easy to understand and is equivalent to this JAVASCRIPT statement:
1 {firstName : "Json"}
The relationship between JSON and JS object Many people do not know the relationship between JSON and JS objects, and even who is not clear. In fact, it can be understood that JSON is a string representation of a JS object, which uses text to represent the information of a JS object, essentially a string. Such as
This is an object, note that the key name can also be wrapped in quotation marks // This is a JSON string, which is essentially a string  
JSON and JS objects to convert from an object to a JSON string, using the Json.stringify () method:
The result is ' {' A ': ' Hello ', ' B ': ' World '} '

To implement a conversion from JSON to an object, use the Json.parse () method:

The result is {a: ' Hello ', B: ' World '}
Common typesEditIn the JS language, everything is an object. Therefore, any supported type can be represented by JSON, such as strings, numbers, objects, arrays, and so on. However, objects and arrays are two of the more special and common types. Object: Object in JS is the contents of the curly brace wrapped {}, the data structure is {key1:value1, key2:value2, ...} key-value pair structure. In an object-oriented language, key is the property of the object, and value is the corresponding values. Key names can be represented using integers and strings. The type of the value can be any type. Array: The array in JS is square brackets [] wrapped content, data structure for ["Java", "JavaScript", "VB", ...] index structure. In JS, an array is a special type of data, and it can also use key-value pairs like objects, but it is still much used by indexes. Similarly, the type of the value can be any type. Basic exampleEditTo put it simply[1],json can convert a set of data represented in a JavaScript object into a string, which can then be easily passed between the network or the program and revert to the data format supported by the programming language when needed, for example, in PHP, where JSON can be Restores an array or a base object. When using AJAX, if you need to use an array to pass values, then you need to use JSON to convert the array into a string. The most common format for representing object JSON is the object's key-value pair. For example, this is the following:
{"FirstName": "Brett", "LastName": "McLaughlin"}
In the same way that an array is represented by a normal JS array, the JSON representation of an array is also using square brackets [].
{"      people": [          {"FirstName": "Brett",             "LastName": "McLaughlin"         },          {             " FirstName ":" Jason "," LastName ":" Hunter " }]}    
It's not hard to understand. In this example, there is only one variable named people, and the value is an array of two entries, each of which is a person's record, which contains the first and last names. The above example shows how to combine records into a single value with parentheses. Of course, you can use the same syntax to represent more values (each value contains multiple records). There are no predefined constraints to follow when working with JSON-formatted data. So, in the same data structure, you can change the way you represent data, or you can represent the same thing in different ways. As mentioned earlier, in addition to objects and arrays, you can simply use strings or numbers to store simple data, but that doesn't make much sense.

Java EE Development Technology Course Week seventh (JSON)

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.