Home  >  Article  >  Web Front-end  >  Why is JSON so popular? Why should we use json (there is another cave)_Basic knowledge

Why is JSON so popular? Why should we use json (there is another cave)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:45:211042browse

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 = '

lenel
';
Then the frontend uses

Copy code The code is as follows:

function toDivElememnt(s){
var oDiv = document.createElement(" div");
oDiv.innerHTML = s;
oDiv = oDiv.firstChild;
return oDiv;
}

I did not use js to explain this method json, but uses DOM to interpret HTML strings, which is quite natural. As mentioned before, HTML strings are also tree structures. After I get oDiv, I can access attributes such as age, personid, etc., and the efficiency is quite good. ,hehe.
This is not my original work, it comes from my former leader, a great person, a good mentor and helpful friend.

Will JSON replace XML?
No, in the field of Ajax we may do Ajaj, but if XML can only do this, it is not XML :)

Haven’t you used JSON yet?
Don’t be left behind, haha. The current mainstream backend languages ​​all have APIs to generate and parse JSON in the backend. How to use json and where to find the API? Let’s take a look at http://www.json.org

Have we really learned anything?
I still haven’t summarized it specifically, but I think the languages ​​​​are similar. Can’t javaScript be IOC?
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