Ajax Learning--The ideal data exchange language JSON

Source: Internet
Author: User

First, the syntax structure of JSON

1. Basic structure

1> a collection of name/value pairs (objects, records, structures, dictionaries, hash tables ...)

A name/value pair is an element, the element name and value are separated by the " : " number, and multiple name/value pairs are combined into a JSON structure, and the name/value pairs are separated by " , ".

Example: JSON structure:

{     "name":  "AJAX",     "sex": "Man"}
2> sequence Table (array) of values

Example:

["AJAX", "HTML", "PHP"]

2. Brace save object, square brackets Save array

3. Objects can hold multiple name/value pairs, and arrays can hold multiple objects

Example:

{"   student": [          {"Name": "Charles", "id": "123"},          {"Lesson": "Math", "Teacher": "Tom"},          {"Address": " AAA "," Number ":" 1 "}]}


Ii. types of values in JSON

1. Object 2. Array 3. Number 4. String 5. Boolean value 6.null


Third, the language support of JSON

There are many languages that support JSON: Javascript, PHP, C #, C, C + +, Java ...

1.JSON is based on JavaScript, so the basic structure of JavaScript native support for Json,json is actually the object and data in JavaScript,

With the function--eval (string) in JavaScript, you can convert the JSON data to a JavaScript object.

Example:

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

Note: The text must be wrapped in parentheses to avoid errors.

The 2.PHP uses Json,json to support JSON from version 5.2, implemented by Json_encode () and Jsno_decode () two methods.

Example:

Suppose $book is an example of an array, a number, and so on, converting $book to JSON format:

$json      
Json_decode () Converts the JSON to a PHP object.


Iv. advantages and disadvantages of JSON

1. Advantages:

1>json is simpler than XML

2> Easy to parse

3> Simple Structure

2. Disadvantages:

There is no namespace mechanism like XML


Ajax Learning--The ideal data exchange language JSON

Related Article

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.