Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does json mean in ajax

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the meaning of json in ajax. It has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let's take a look at it.

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

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Basic concepts of Ajax-JSON

Basic concepts of JSON

JSON, whose full name is "JavaScript Object Notation", is a data format that can be transferred between different languages and 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 gets a JSON data

Comparison between json and xml

Xml is also a way to convey information.

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

2. Json can read and write faster.

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

Json grammar 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), and the value pair is written in the back (also in double quotation marks), separated by colons, such as "name": "Guo Jing".

Unlike the javaScript object representation, the key value of the javaScript object representation does not need quotation marks, but the key value of json is in quotation marks.

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

(1) numbers (integers or floating point numbers), such as 123

(2) string (in double quotes)

(3) logical value (true or false)

(4) Array (in square brackets)

(5) object (in curly braces)

(6) null

3. Typical examples of json:

{"staff": [{"name": "Hong Qi", "age": 70}, {"name": "Guo Jing", "age": 35}]}

Json parsing

1. Json is parsed in js in two ways: eval and JSON.parse

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

Var jsonval= {"staff": [{"name": "Hong Qi", "age": 20}, {"name": "Hong Qi 2", "age": 20}, {"name": "Hong Qi 3", "age": 20}]}

1) eval ()

Var jsonbj= ('('+ jsonval+')');-parse jssonbj.employees [0] .firstName-visit

2) JSON.parse ()

Var data = JSON.parse (jsonval);-analyze jssonbj.employees [0] .firstName-visit and thank you for reading this article carefully. I hope the article "what is the meaning of json in ajax" shared by the editor will be helpful to you. At the same time, I hope you will support us, pay attention to the industry information channel, and more related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report