In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the meaning of the JSON file, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
JSON stands for JavaScript object representation. The JSON file has a .json extension, and the data in it is represented by key: value pairs, just like traditional JavaScript objects. However, JSON and object are not exactly the same. The core difference is that the key in JSON must be in double quotes, and values other than number and null must also be double quotes. If you've used API in your programming, you probably know what JSON is, because a lot of API data is now in JSON format.
Basic JSON syntax {"key1": "value1", "key2": "value2", "key3": "value3", "key4": 7, "key5": null, "favFriends": ["Kolade", "Nithya", "Dammy", "Jack"], "favPlayers": {"one": "Kante", "two": "Hazard", "three": "Didier"} accepted JSON data types
JSON can be defined in an object or an array, and it may contain multiple objects. Therefore, objects and arrays are automatically acceptable data types in JSON. Other data types it supports are Boolean values, null values, and strings.
JSON does not support data types such as undefined, function, and date.
In addition, JSON can be extended to other data formats that may accept additional data types that are not accepted by the original JSON.
Examples of such extensions are GeoJSON and BSON. GeoJSON is used to represent geographic data, while MongoDB, a popular database service provider, uses BSON.
For example, BSON accepts regular expressions, date and timestamps as data types, while JSON does not.
JSON grammar rules
JSON is very strict in terms of supported data types. If you install linter in the code editor, it immediately notifies you of an error when you enter an unsupported data type or violate syntax rules.
JSON syntax rules to know:
If you represent a file as an object, all data in the file must be enclosed in curly braces, or if it is an array, it must be enclosed in square braces.
Single quotation marks are not allowed
The keys in each JSON must be unique and must be enclosed in double quotation marks
Numbers cannot be enclosed in double quotation marks, otherwise they will be treated as strings.
Empty data types cannot be enclosed in double quotation marks.
Boolean values can only be true or false.
Except for the last item, each key-value pair must end with a comma
Specific objects in the array must also end with a comma.
How JSON data is sent to the client (browser)
JSON is created out of the need to send data from a server (such as a database) to the client (browser) in real time.
However, JSON data cannot be transferred to the browser in the form of its original key-value pair, so the programming language has a way to manipulate JSON data.
For example, in JavaScript, JSON.parse () converts JSON data to an object, JSON.stringify (), and converts the object's key-value pairs to JSON data.
Python provides methods such as json.loads () to convert existing strings to JSON and json.dumps () to convert objects to JSON strings.
You can use the two methods provided by JavaScript to send data from the basic JSON syntax to the browser.
How to use JavaScript to send JSON data to the client (browser)
The JSON.stringify () method returns an JSON string that is exactly the same as the JavaScript object. You can use it in conjunction with the DOM action method to display JSON data in the browser, as I did in the following code snippet:
Here is the Data from the JSON: const JSONData = {"key1": "value1", "key2": "value2", "key3": "value3", "key4": 7, "key5": null, "favFriends": ["Kolade", "Nithya", "Dammy", "Jack"], "favPlayers": {"one": "Kante", "two": "Hazard" "three": "Didier"}} const JSONString = JSON.stringify (JSONData) const JSONDisplay = document.querySelector ("# json") JSONDisplay [XSS _ clean] = JSONString
In the JavaScript code, we declare the JSON data as an object literal JSONData with an identifier (name). We use the JSON.stringify () method of JavaScript to convert it to a string and use the query selector method of DOM to get the empty div in HTML. This makes it possible to populate the JSON data in it using the innerHTMLDOM operation method.
We can use this JSON.parse () method to convert JSON data to an object-- it's running:
Here is the Data from the JSON:const JSONData ='{"name": "Kolade", "favFriends": ["Kolade", "Nithya", "Rocco", "Jack"], "from": "Africa"}'; try {const JSONString = JSON.parse (JSONData); const JSONDisplay = document.querySelector ("# json"); JSONDisplay [JSONString.favFriends _ clean] = JSONString.name + ", [" + JSONString.favFriends + "]," + JSONString.from } catch (error) {console.log ("Cannot parse the JSON Data");}
The result output in the browser is as follows:
Thank you for reading this article carefully. I hope the article "what is the meaning of JSON file" shared by the editor will be helpful to everyone? at the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.