What does json in ajax mean?

青灯夜游
Release: 2022-01-19 17:24:06
Original
2580 people have browsed it

In ajax, json is a data format that can be transferred between different languages. It is a lightweight data exchange format, which is used to exchange data between the browser and the server. JSON is easy to understand and data exchange is faster than XML; it supports arrays, objects, strings, numbers, and values.

What does json in ajax mean?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Ajax-JSON basic concept

JSON basic concept

JSON full name" "JavaScript Object Notation" is a data format that can be transferred between different languages, a lightweight data exchange format.

In AJAX, it is used to exchange data between the browser and the server. It's easy to understand and data exchange is faster than XML. It supports arrays, objects, strings, numbers and values.

Send a request through AJAX, and the server obtains a JSON data

Comparison between json and xml

xml is also a method of transmitting information .

1. The length of json is very short compared to the xml format.

2. The speed of reading and writing json is faster.

3. json can be parsed directly using the built-in method of javaScript and converted into a javaScript object, which is very convenient.

json syntax rules

1. The writing format of json data is: name/value pair.

The name in the name/value pair combination is written in front (in double quotes), the value pair is written in the back (also in double quotes), separated by colons, such as "name":"Guo Jing ".

Different from javaScript object notation, the key values ​​​​of javaScript object notation do not need to be quoted, but the key values ​​​​of json must be quoted.

2. The value of json can be of the following types:

(1) Number (integer or floating point number), such as 123, 1.23

(2) String ( in double quotes)

(3) logical value (true or false)

(4) array (in square brackets)

(5) object (in flower In brackets)

(6) null

3. Typical example of json:

{
  "staff":[
    {"name":"洪七","age":70},
    {"name":"郭靖","age":35}
  ]
}
Copy after login

json parsing

1. json in There are two ways to parse in js: eval and JSON.parse

2. It is very dangerous to use eval in code, especially using it to execute third-party JSON data (which may contain malicious code)

var jsonval= {"staff": [{"name": "洪七","age": 20}, {"name": "洪七2","age": 20}, {"name": "洪七3","age": 20}]}
Copy after login

1) eval()

var jsonbj=('('+jsonval+')');----解析
jssonbj.employees[0].firstName----访问
Copy after login

2) JSON.parse()

var data = JSON.parse(jsonval);---解析
jssonbj.employees[0].firstName----访问
Copy after login

[Related tutorial recommendations: AJAX video tutorial]

The above is the detailed content of What does json in ajax mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!