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
XML code:
中国 黑龙江 哈尔滨 大庆 广东 广州 深圳 珠海 台湾 台北 高雄 新疆 乌鲁木齐
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!