JSON Learning Notes

Source: Internet
Author: User

              Json

Full Name:--javascript object notation. (JavaScript Object Notation)

Official website: www.json.org

Description: Both JSON and XML are used for data transfer, they are small and convenient and easy to interact with JavaScript

File type of files: " . JSON "

MIME type of text: "application/json"

Conditions of Use: Import related package Net.sf.json{

Commons-beanutils-1.7.0.jar

Commons-collection-3.1.jar

Commons-lang-2.5.jar

Commons-logging.jar

Ezmorph-1.0.6.jar

Json-lib-2.4-jdk15.jar

}

Package of Baidu Cloud Link: (To fill)

I. Basic information of JSON

1. He is a lightweight text data interchange format.

2. In syntax, JSON syntax is a subset of JavaScript syntax

{It uses JavaScript syntax to describe the data object, which is syntactically identical to the code that created the JavaScript object and can be parsed directly from JavaScript

( Note:JavaScript programs can use the built-in eval () function to generate native JavaScript objects with JSON data.) )

}

3.JSON data can be transmitted using AJAX.

4.JSON VS XML (comparison of JSON versus XML)

  json XML
data readability Same same
analytic means /span> also rich also rich
data volume small td> large
interaction with JavaScript more convenient  
Descriptive of the data poor good

Two. Syntax rules for JSON

1. Data format: "Variable name": value, such as: "FirstName": "John"

2. Object: Save,--> {} with curly braces

3. Array: Save,--> in square brackets []

4. Data separation: comma (comma),-->,

Three. JSON data type (6 types)

1. Null (NULL)--NULL

2. Boolean value (Boolean)-->true/false

3. Numeric value (number) and direct data

4. Strings (string)--"strings"

5. Arrays (array)--[content]

6. Objects (object)---{Object Properties}

Notes

1. The array can contain multiple objects, such as:

    

That is, the object employees has three sub-objects, each of which has two properties

Four. Alternative assignment methods for JSON

1. Using JavaScript to assign values, such as:

1 var employees = [2 {"FirstName": "Bill", "LastName": "Gates"},3 {" FirstName ":" Json "," LastName ":" Well "}4]; 5 // Accessing Data 6 // Back to Gates 7 // Modifying Data 8 employees[0].lastname = "Gall";

Five. Object conversion between JSON and JavaScript

1.JSONObject Objects --Convert----> (#3bc359) JavaScript

One of the most common usages of--json.

-- That is, the JSON data is read from the Web server (as a file or as a httprequest), and the JSON the data is converted to a JavaScript object, and then the data is used in the Web page.

  (pending)

2.JavaScript Object--Convert---->jsonobject object

    (pending)

  3. Using JavaScript objects

<P>FirstName:<spanID= "FName"></span><BR/>LastName:<spanID= "LName"></span><BR/></P><Scripttype= "Text/javascript">document.getElementById ("fname"). InnerHTML=obj.employees[0].firstname; document.getElementById ("lname"). InnerHTML=obj.employees[0].lastname;</Script>

Six. Conversion between Jsonobject and map<string,string>

(pending)

JSON Learning Notes

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.