JSON Quick Start

Source: Internet
Author: User

http://www.json.org/

Documnt:http://stleary.github.io/json-java/index.html

JSON QuickStart (Java edition) http://www.imooc.com/learn/523

Turn from: Ruan Yi Feng Great god's "data type and JSON format" http://www.ruanyifeng.com/blog/2009/05/data_types_and_json.html

 Nanyi Date: May 30, 2009 1. A few days ago, I learned that there is a simplified data interchange format called YAML. I rummaged through its documentation, not much to understand, but there was a word that made me enlightened.    It says that, structurally, all data can eventually be decomposed into three types: the first type is a scalar, or a single string or a number (numbers), such as "Beijing", a separate word.    The second type is the sequence (sequence), which is a number of related data that are tied together in a certain order, also called an array or list, such as "Beijing, Shanghai." The third type is mapping (mapping), a name/value pair (Name/value), which has a name and a value corresponding to it, also known as hash (hash) or dictionary (dictionary), such as "Capital: Beijing". It dawned on me that the smallest unit of data composition was so simple! No wonder in programming languages, as long as you have arrays and objects (object), you can store all the data. 2. I immediately thought of JSON. At the beginning of 21st century, Douglas Crockford looked for a simple data interchange format that could exchange data between servers. The universal data Exchange language was XML at the time, but Douglas Crockford thought that XML generation and parsing were too cumbersome, so he proposed a simplified format, json.    JSON specifications are very simple, with only one page hundreds of words can be said clearly, and Douglas Crockford claims that this specification never need to upgrade, because the provisions of the provision.    1) The data is separated by commas (",").    2) The map is represented by a colon (":").    3) a set (array) of side data is expressed in square brackets ("[]"). 4) The Set of Mappings (objects) are represented by curly braces ("{}"). The above four rules are all content in JSON format. For example, the following sentence: "Beijing's area of 16800 square kilometers, the resident population of 16 million people." The area of Shanghai is 6400 square kilometers, the resident population is 18 million. "The JSON format is like this: [{" City ":" Beijing "," area ": 16800," Population ": 1600}, {" City ":" Shanghai "," area ": 6400," Population ": 1800}] If you know the structure of the data beforehand, the above can be written in a Step simplification: [["Beijing", 16800,1600], ["Shanghai", 6400,1800]] It can be seen that JSON is easy to learn and use. So, in just a few years, it replaced XML as the most popular data interchange format on the Internet. I suspect that Douglas Crockford must have known beforehand that the data structure can be simplified into three forms, otherwise how can the JSON be defined so refined! 3. When I was learning JavaScript, I had no idea where the fundamental difference between array and object is, and both can be used to represent a collection of data. For example, there is an array a=[1,2,3,4], there is an object A={0:1,1:2,2:3,3:4}, and then you run alert (a[1]), the results of the operation are the same in both cases! This means that the data collection can be represented either as an array or as an object, so which one should I use? I later learned that an array represents a collection of ordered data, whereas an object represents a collection of unordered data. If the order of the data is important, use an array, or you will use the object. 4. Another difference between arrays and objects, of course, is that the data for the array has no name, and the object's data has a name. But the problem is that in many programming languages, there is something called an associative array (associative array). The data in this array is named.    In JavaScript, for example, you can define an object like this: Var a={"city": "Beijing", "area": 16800, "Population": 1600}; However, it can also be defined as an associative array: a["City"]= "Beijing";    a["Area"]=16800; a["Population"]=1600; this at first also exacerbated my confusion with arrays and objects, and later realized that in the JavaScript language, an associative array is an object, and an object is an associative array. This is completely different from the PHP language, where associative arrays are arrays as well.    such as running the following paragraph Javascript:var a=[1,2,3,4];    a[' foo ']= ' Hello world '; alert (a.length); The final result is 4, which means that the number of elements in array A is 4.    However, the PHP code that runs the same content is different: <?php $a =array (1,2,3,4);    $a ["foo"]= "Hello World";    echo count ($a); The final result of?> is 5, which means that the number of elements in array A is 5.

-----1--------------------------------------------------------------------------------

JSON is a lightweight data format, and key must be of type string. Simplicity is the biggest reason for its popularity. The full name is JavaScript Object Notation.

JSON: Requires the character set to be Unicode

Four basic rules for JSON:
1) The data is separated by commas (",").
2) The map is represented by a colon (":").
3) a set (array) of side data is expressed in square brackets ("[]").
4) The Set of Mappings (objects) are represented by curly braces ("{}").

---1.2 Data types represent---------------------------------------------------------------------------------
Data structure: Object, Array
Base type: String,number,true,false,null
(1) Object {key:value,key:value ...}
The key:string type.
Value: Any basic type or data structure.
(2) Array [Value,value ...]
Value: Any basic type or data structure.

Note ("Birthday": "1990-01-01",): JSON does not have a date type definition in the data format specification, either in the string type or with a timestamp.

{
"Name": "Wangxiao",
"Age": 25.2,
"Birthday":"1990-01-01",
"School": "Blue Xiang",
"Major": ["Barber", "excavator"],
"Has_girlfriend": false,
"Car": null,
"Comment": "JSON does not support any form of comment"
}

----1-3 JSON using--------------------------------------------------------------------------------

http://www.json.org/

http://www.jsoneditoronline.org JSON editor

Documnt:http://stleary.github.io/json-java/index.html

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

---------------------------------------------------------------------------------

JSON Quick Start

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.