The content this article brings to you is about the application of JSON syntax in js in the front-end. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Front-end---JSON syntax in js
JSON syntax is a subset of JavaScript syntax. JSON (JavaScript Object Notation) syntax provides a simpler way to create objects. Using JSON syntax can avoid writing functions or using the new keyword, and you can directly create a JavaScript object. To create a JavaScript object, use curly braces and write each property as a "key:value" pair.
JSON syntax rules
JSON syntax is a subset of JavaScript object representation syntax.
Data is in name/value pairs Data is separated by commas Curly brackets save the object Square brackets save the array
JSON name/value pair
JSON data The writing format is: name/value pair.
The name/value pair consists of the field name (in double quotes), followed by a colon, and then the value:
"name" : "Novice Tutorial"
This It is easy to understand and is equivalent to this JavaScript statement:
name = "Rookie Tutorial"
JSON value
The JSON value can be:
Number (integer or floating point number) String (in double quotes) Logical value (true or false) Array (in square brackets) Object (in curly brackets) null
JSON number
JSON number can be integer or floating point:
{ "age":30 }
JSON object
JSON objects are written in curly brackets ({}):
Objects can contain multiple name/value pairs:
{ "name":"Rookie Tutorial", "url":"www .runoob.com" }
This is easy to understand and is equivalent to this JavaScript statement:
name = "Rookie Tutorial" url = "www.runoob.com"
JSON array
JSON array is written in square brackets:
The array can contain multiple objects:
{ "sites": [ { "name":"菜鸟教程" , "url":"www.runoob.com" }, { "name":"google" , "url":"www.google.com" }, { "name":"微博" , "url":"www.weibo.com" } ] }
In the above example , the object "sites" is an array containing three objects. Each object represents a record about a website (name, url).
The above is a complete introduction to the application of JSON syntax in js in the front-end. If you want to know more about JavaScript video tutorial, please pay attention to the PHP Chinese website .
The above is the detailed content of Application of JSON syntax in js in front-end. For more information, please follow other related articles on the PHP Chinese website!