Home  >  Article  >  Web Front-end  >  Why is json commonly used?

Why is json commonly used?

青灯夜游
青灯夜游Original
2019-05-31 17:57:122929browse

Why is json commonly used?

What is JSON?

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. It is easy for people to read and write, and it is also easy for machines to parse and generate, and effectively improves network transmission efficiency.

JSON vs. XML comparison

Why is json commonly used?

XML code:

<?xml version="1.0" encoding="utf-8"?>
<country>
    <name>中国</name>
    <province>
        <name>黑龙江</name>
        <cities>
            <city>哈尔滨</city>
            <city>大庆</city>
        </cities>
    </province>
    <province>
        <name>广东</name>
        <cities>
            <city>广州</city>
            <city>深圳</city>
            <city>珠海</city>
        </cities>
    </province>
    <province>
        <name>台湾</name>
        <cities>
            <city>台北</city>
            <city>高雄</city>
        </cities>
    </province>
    <province>
        <name>新疆</name>
        <cities>
            <city>乌鲁木齐</city>
        </cities>
    </province>
</country>

JSON code:

{
    "name": "中国",
    "province": [{
        "name": "黑龙江",
        "cities": {
            "city": ["哈尔滨", "大庆"]
        }
    }, {
        "name": "广东",
        "cities": {
            "city": ["广州", "深圳", "珠海"]
        }
    }, {
        "name": "台湾",
        "cities": {
            "city": ["台北", "高雄"]
        }
    }, {
        "name": "新疆",
        "cities": {
            "city": ["乌鲁木齐"]
        }
    }]
}

JSON code hierarchy is clearer and easier to read. Due to the simplicity of characters, JSON is better than XML during data transmission and can reduce the bandwidth occupied by data transmission

Why use JSON?

Reasons for using JSON:

● JSON data is clear

● JSON has many tool classes to support its conversion

● JSON in all Mainstream browsers have good support

● JSON has a smaller data volume during transmission

● JSON has a natural language advantage in JS (because it is a standard subset)

The above is the detailed content of Why is json commonly used?. 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