Home > Article > Web Front-end > Why is JSON so popular? Why should we use json (there is another cave)_Basic knowledge
json is something that has quickly become popular all over the world within a year.
Now that I explain what JSON is, everyone will say that I am old-fashioned. Here I want to analyze the reasons why JSON is red and what enlightenment we can get.
What is json? json.org is a concise and effective data carrier. It is a way to use strings to represent complex js objects. The backend is easy to generate and the frontend has no explanation.
Its popularity is inseparable from the following reasons.
Persistence trend:
Persistence is an important module introduced by javaEE5.
PHP has the inherent persistence feature. Each variable can be serialized() and unserialize() and converted into strings.
The most direct benefit brought by persistence is the storage and transmission of complex objects. An important criterion for measuring the quality of the persistence mechanism is efficiency.
The promotion of WEB2.0:
Ajax triggered the Web2.0 revolution, where x is xml. In Ajax, XML is used as a carrier for front-end and back-end data transmission.
With the large-scale application of Web2.0, the efficiency problem of xml interpretation has been undoubtedly exposed. xml has a very strictly prohibited structure, which causes any browser to load xml and interpret it into objects that can be accessed by javascript. The process is long. JSON is the simplest object creation method supported by JS by default. It is easy and pleasant for JS to receive it, so in the arena of persistent data transmission, JSON wins by efficiency.
JSON itself is easy to use:
Why is Ajax suddenly popular when combined with some old technologies? Because it is easy to use. To put it bluntly, since the advent of DHTML in the last century, xmlHttpRequest is not the only solution to refresh-free asynchronous data transmission. Hidden iframes can definitely be done, and people do it all the time. Ajax is popular because of its ease of use, so the large-scale application of several leading companies triggered Web2.0.
JSON is also easy to use. After knowing JSON, I have used var obj = {};var arr = [ ] instead of var obj = new Object(); var obj = new Array(). JSON is the most concise object definition method in js. For those who know js and have used eval(), there is basically no learning cost.
The popularity of tree structures represented by XML:
Look at the popularity of xml from the perspective of data structure, because xml is a tree, and tree-like data structures are used in things like Everyone knows the power of xml in addition to its own content nodes plus attribute nodes. DOM has this structure, and UML has this structure.
When we use data to describe the objective world, we find that relying solely on two-dimensional tables in the relational data model is clumsy. The tree structure is closer to thinking. This is why people no longer use Notepad when taking meeting minutes. And the reason for using freemind. Also using a two-dimensional table, the inefficiency of storing the tree by recording parentid also gives LADP room for development.
Speaking of JSON, it is a way to define JS objects, and Object in JS is an entity organized in the form of a tree, so the objects defined by JSON are sufficient in describing the function of data.
Let’s talk about a few more JSON-related topics:
Is JSON the only way to solve the xml efficiency problem?
Not necessarily. Before I knew json, I was using div to transmit data.
What is passed from the background to the front is xmlHttp.responseText = '