Home  >  Article  >  Web Front-end  >  What does json mean? What is it used for?

What does json mean? What is it used for?

不言
不言Original
2018-10-15 11:20:0150219browse

This article is mainly to introduce you to the concept of json and what json can be used for. Friends in need can take a look.

First let’s take a look at What does json mean?

According to the explanation on Baidu Encyclopedia, we can know: JSON (JavaScript Object Notation, JS Object Notation) is a lightweight data exchange format. It is based on a subset of ECMAScript (the js specification developed by the European Computer Association) and uses a text format that is completely independent of programming languages ​​to store and represent data. Simplicity and clear hierarchical structure make JSON an ideal data exchange language.

In fact, simply speaking, json is a data exchange format. So what is the data exchange format json used for? Let’s take a closer look below.

json is a data format that has the same function as an array and is used to store data.

For example, for a person's personal information, an array can be used to store it like this

var tom = ['Tom', '29', '170', 'man'];

If a rule is agreed upon, we can use such an array to save tom's information, namely name = tom[0 ], age = tom[1], height = [2], gender = tom[3]

But obviously this is not a good solution. We usually fill in data with tables. Know better

Name
Age
Height
Gender
Tom
29
170
man
Jake
22
175
man

So with json, use key-value mode to store data more intuitively

var tom = {
    name: 'tom',
    age: '29',
    stature: 170,
    gender: 'man'
    
}

It is also very simple to access attributes. In the array we use The sequence index is used to access the specific value, while in json, key is used to access the value

For example, to access the age

var age = tom.age;

If there are many people, a combination of array and json will be used. Here is the code way to express the content of the above table

var data = [
    {
        name: 'tom',
        age: '29',
        stature: 170,
        gender: 'man'
    },
    {
        name: 'jake',
        age: '22',
        stature: 175,
        gender: 'man'
    }
]

In this table, I want to get jake’s height

var jakeSta = data[1].stature

The writing method of json mode is also called object literal in ECMAScript. It can not only simply To store values, you can also store functon

var test = {
    name: 'tom',
    function: getName() {
        return test.name;
    }
}

json, which can also be used to transfer json data between the front and back ends. For example, the front end initiates a request and calls the interface, and the back end returns a string of json data, processes the data, and renders it on the page.

This article ends here. For more exciting content about json, you can pay attention to the php Chinese website! ! !

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

Statement:
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