Home > Web Front-end > JS Tutorial > body text

Application of JSON syntax in js in front-end

云罗郡主
Release: 2018-10-12 16:36:36
forward
2325 people have browsed it

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.

Application of JSON syntax in js in front-end

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" } ] }
Copy after login

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!

source:2cto.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!