Home > Article > Web Front-end > What is JSON and how to use it
The content of this article is to introduce what is JSON? How to use it, so that everyone can have a preliminary understanding of JSON and know the simple usage of JSON. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
First of all, let’s understand what JSON is? What is the use?
JSON, the full name is JavaScript Object Notation, which is JavaScript object notation. It is a Text-Based lightweight (Light-Weight) open standard designed for human-readable (Human-Readable) data exchange. Programmers already know the conventions used by JSON, including C, C#, Java, Python, Perl, etc.
To summarize:
1. JSON is a JavaScript object notation, extended from the JavaScript scripting language.
2. JSON adopts a completely language-independent text format, but it can also use habits similar to the C language family (including C, C, C#, Java, JavaScript, Perl, Python, etc.).
3. The file extension is .json, the unified type identifier is public.json, and the Internet Media type is application/json.
4. JSON is designed for human-readable data exchange.
Characteristics of JSON:
1. JSON is a lightweight text-based data exchange format.
2. It is very easy to read and write, both for people and machines, and is smaller than XML files;
3. JSON is very easy to write. Simple and clear at a glance; it complies with the native JavaScript syntax and can be directly processed by the interpretation engine without adding additional parsing code.
4. JSON has nothing to do with language
Simply put: JSON is a method of storing information in an organized, easy-to-access and written format; it provides us with a human-readable A collection of data that we can access in a very reasonable way.
Let’s take a look at where JSON can be used? how to use?
Usage of JSON
1. Use it when writing JavaScript-based applications that include browser extensions and websites.
2. The JSON format is used to serialize and transmit structured data through network connections.
3. It is mainly used to transfer data between servers and web applications.
4. Web services and APIs use JSON format to provide public data.
5. It can be used with modern programming languages.
Simple example of JSON
Let’s take a look at how to use JSON through a simple example
Example 1: Show how to use JSON according to theme and version Stores information related to books.
{ "book": [ { "id":"01", "language": "Java", "edition": "third", "author": "Herbert Schildt" }, { "id":"07", "language": "C++", "edition": "second", "author": "E.Balagurusamy" } ]}
Example 2: After understanding the above procedure, we will try another example. We save the following code as json.htm
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JSON example</title> <script language = "javascript" > var object1 = { "language" : "Java", "author" : "herbert schildt" }; document.write("<h1>JSON与JavaScript示例</h1>"); document.write("<br>"); document.write("<h3>Language = " + object1.language+"</h3>"); document.write("<h3>Author = " + object1.author+"</h3>"); var object2 = { "language" : "C++", "author" : "E-Balagurusamy" }; document.write("<br>"); document.write("<h3>Language = " + object2.language+"</h3>"); document.write("<h3>Author = " + object2.author+"</h3>"); document.write("<hr />"); document.write(" 一本可研究编程语言: " +object2.language + "的书,作者 " + object2.author); document.write("<hr />"); </script> </head> <body> </body> </html>
Running effect:
Summary: The above is the entire content of this article, I hope it can be helpful to everyone Learning helps.
The above is the detailed content of What is JSON and how to use it. For more information, please follow other related articles on the PHP Chinese website!