Home > Common Problem > body text

What is json format

coldplay.xixi
Release: 2020-10-30 11:28:03
Original
17775 people have browsed it

There are two json formats, namely: 1. Object format [{"key1":obj, "key2":obj, "key3":obj...}]; 2. Array or collection format , [[obj,obj,obj...]].

What is json format

The role of json (json is a language-independent data exchange format)

  • Use ajax for front-end and back-end data exchange

  • Data exchange between mobile terminal and server

It is convenient to use Json format and parsing Represents an object information, json has two formats:

1) Object format: {"key1":obj,"key2":obj,"key3":obj...}

2) Array/collection format: [obj, obj, obj...]

For example: the user object is represented in json data format

{"username":"zhangsan","age":28,"password":"123","addr":"北京"}
Copy after login

List json data format representation

[{"pid":"10","pname":"小米4C"},{},{}]
Copy after login

As long as it is an object, use {enclosed}, as long as it is a collection, use []enclosed

Note: Object format and array format can be nested in each other, an object An attribute in can be a collection or array

The key of json is a string and the value of json is Object

What is json format

This object contains username, age , password, addr, account attributes, where the value of the account attribute is also an object

Example

After we write the object in json format, we want to get this The attributes of the object can be obtained by just clicking on the object level one level like Java. See the following example

What is json format

This one has a person object, person.lastname You can directly get the value of person's lastname

What is json format

This person is a collection, there are two objects in the collection, person[1] is the first object in the collection

What is json format

json is an object. This object has an attribute baobao. The value of baobao is a collection, json. baobao[1] is the first object to obtain the baobao value

What is json format

This json is an object with three attributes. The first attribute is a simple value. The second attribute is an object, and the third attribute is a collection.

The above things are all written in <script>, so json is the native content of js, which means that js can directly To take out the data in the json object, as long as the var object name = json format object, we can directly obtain the data in the object through the name of the object format in js without parsing </script>

Related free recommendations: Programming Video Course

The above is the detailed content of What is json format. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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