Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic syntax of JSON

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 relevant knowledge of "what is the basic grammar of JSON". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "what is the basic grammar of JSON" can help you solve the problem.

JSON: JavaScript Object Notation (JavaScript object representation), JSON is the syntax for storing and exchanging text information, similar to XML,JSON, which is smaller, faster, and easier to parse than XML.

JSON grammar rules

The JSON syntax is a subset of the syntax represented by JavaScript objects.

Data in name / value pairs data is separated by commas in curly braces save objects in parentheses save array JSON name / value pairs

The writing format of JSON data is: name / value pair.

The name / value pair includes the field name (in double quotes), followed by a colon, followed by the value:

"name": "Rookie course"

This is easy to understand and is equivalent to this JavaScript statement:

Name = "rookie tutorial" JSON value

The JSON value can be:

Numeric (integer or floating point) string (in double quotes) logical values (true or false) array (in square braces) objects (in curly braces) nullJSON digits

JSON numbers can be integer or floating point:

{"age": 30} JSON object

The JSON object is written in curly braces ({}):

An object can contain multiple name / value pairs:

{"name": "Rookie tutorial", "url": "www.runoob.com"}

This is also easy to understand and is equivalent to this JavaScript statement:

Name = "rookie tutorial" url = "www.runoob.com" JSON array

The JSON array is written in square brackets:

An array can contain multiple objects:

{"sites": [{"name": "Rookie tutorial", "url": "www.runoob.com"}, {"name": "google", "url": "www.google.com"}, {"name": "Weibo", "url": "www.weibo.com"}]}

In the above example, the object "sites" is an array of three objects. Each object represents a record about a website (name, url).

JSON Boolean value

The JSON Boolean value can be true or false:

{"flag": true} JSON null

JSON can set the null value:

{"runoob": null} JSON uses JavaScript syntax

Because JSON uses the JavaScript syntax, no additional software is needed to handle JSON in JavaScript.

With JavaScript, you can create an array of objects and assign values like this:

Example

Var sites = [{"name": "runoob", "url": "www.runoob.com"}, {"name": "google", "url": "www.google.com"}, {"name": "Weibo", "url": "www.weibo.com"}]

You can access the first item in the array of JavaScript objects like this (the index starts at 0):

Sites [0] .name

The returned content is:

Runoob

You can modify the data like this:

Sites [0] .name = "Rookie tutorial"

JSON file the file type of the JSON file is ".json" the MIME type of the JSON text is "application/json" about "what is the basic syntax of JSON". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report