Home >Common Problem >What is json format
There are two json formats, namely: 1. Object format [{"key1":obj, "key2":obj, "key3":obj...}]; 2. Array or collection format , [[obj,obj,obj...]].
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":"北京"}
List
[{"pid":"10","pname":"小米4C"},{},{}]
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
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
This one has a person object, person.lastname You can directly get the value of person's lastname
This person is a collection, there are two objects in the collection, person[1] is the first object in the collection
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
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!