JSON Getting Started learning case note

Source: Internet
Author: User

What 1.JSON is:

JSON, or JavaScript Object Notation, is a lightweight data interchange format that is ideal for server-to-javascript interaction. JSON (JavaScript Object Notation) is a lightweight data interchange format. Easy to read and write, but also easy to machine parse and generate. It is based on a subset of JavaScript. JSON takes a completely language-independent text format, but also uses a similar idiom to the C language family (c, C + +, C #, Java, JavaScript, Perl, Python, etc.). These features make JSON an ideal data exchange language.

JSON is a text-based, Open Data Interchange format. Like XML, it is easy for readers to read, platform-independent, and broad-based. Data formatted according to the JSON standard is lightweight and can be easily parsed by JavaScript, making it an ideal data interchange format for Ajax Web applications. JSON is primarily a data format, so it is not limited to Ajax Web applications, and in any case it can be used whenever the application needs to exchange or store structured information as text.

JSON is inherently prepared for JavaScript, so the JSON data format is very simple, you can transfer a simple string,number,boolean with JSON, or you can transfer an array, or a complex object.

JSON (JavaScript Object natation): is a lightweight data interchange format that, like XML, can express data such as String, number, Boolean, array, or even object, based on a plain-text data format

For server-to-JavaScript interaction, JSON is actually a subset of JavaScript syntax.

Background of 2.JSON Appearance:

Many of the hype about how XML has cross-platform, cross-language advantages, but: unless applied to web Services, developers often have a headache with parsing XML in common Web applications, whether the server-side generates or processes XML, or the client uses JavaScript to parse XML, often leading to complex code, very low development efficiency. In fact, for most Web applications, they don't need complex XML to transmit data at all, and XML extensibility is rarely an advantage, and many AJAX applications even return HTML fragments directly to build dynamic Web pages. Returning HTML fragments greatly reduces the complexity of the system compared to returning XML and parsing it, but at the same time lacks some flexibility. The advent of JSON can be said to meet this need. Easily integrate into HTML pages to meet AJAX requirements.

JSON to be Web another format for data exchange is provided by the application developer. JSON provides better simplicity and flexibility than XML or HTML fragments .

3. Representation of a value


string, numeric value, True, False, null, object, or array, and so on.

String

"abc", "\ r \ n", "\U00A9"

Numerical

123,-123.5

Boolean

True, False

Null

 The object is an unordered"'name/value'the"collection. An object to"{" (opening parenthesis),"} " (closing parenthesis) ends. Each"name"followed by a":" (colon);"'name/value'the"Used between"," (comma) delimited.

An array is an ordered collection of values (value). An array begins with "[" (the left square bracket), and "]" (the right square bracket) ends. Use "," (comma) to separate values.

Array representation

Use [] to include all elements, each element separated by commas, and the element can be any value.

Like what:

["ABC", 123, true, NULL]

Access the elements, using the index number, starting with 0.

Complex data representation

The value in an object or array can also be another object or array to represent more complex data

Like what:

List list=new ArrayList ();

List.add (EMP)

[

{"Name": "Zhang San", "Age": "Loves": ["reading", "playing the Game"]},

{"Name": "Harry", "age": +, "loves": ["Travel"]}

]

The value (value) can be a string enclosed in double quotation marks (string), a numeric value (number), True, false, NULL, an object, or an array. These structures can be nested.

Object indicates

The {} contains a series of unordered Key-value key-value pairs, where the key and value are separated by a colon, and each key-value is separated by commas.

Like what:

{"BookName": "Ajax Basics",

"publisher": "Electronic Industry Press",

"Price": 56.0

}

Access to the data, through the Obj.key to obtain the corresponding value

4.JSONwith theXMLCompare 

2 readability JSON and XML are comparable in readability, one side is the proposed syntax, one side is the canonical label form, it is difficult to distinguish the outcome.

2 Extensibility XML is inherently extensible, JSON of course, there is nothing XML can extend, JSON can not.

2 Coding Difficulty XML has a wealth of coding tools, such as dom4j, Jdom, and so on, JSON also has json.org tools, but JSON is much easier to encode than XML, even if the use of tools can write JSON code, but to write good XML is not easy.

2 the parsing of the decoding difficulty XML takes into account the child node parent node, which makes the person dizzy, and the JSON parsing difficulty is almost 0.

2 The popularity of XML has been widely used in the industry, and JSON has only just begun, but in the specific area of Ajax, the future development must be XML to be located in JSON. Ajax should become Ajaj (asynchronous JavaScript and JSON).

5. Conversion

<!--

How text Format data resolves to Objects : using the eval () function of JavaScript

-

For example:

<script type= "Text/javascript" >

var j= "{' name ': ' insolent ', ' age ': +}";

var obj=eval ("(" +j+ ")");

alert (obj.name);

</script>

Jqeury's approach to working with JSON-formatted data

$.getjson (URL [, data] [, callback])

URL is required, the server URL address of the request

Data optional, passed parameters, in the format {name:value,...}

Callback optional, parameter of callback function, is already parsed JSON object


5.JSON Application Example: The following code shows that JSON stores data much simpler than XML

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


The following code shows how JSON simplifies the creation of JavaScript objects

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">



JSON Getting Started learning case note

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.