This article mainly introduces the knowledge of JSON data structures. For more information about JSON data structures, see the recently developed platform. If you want to use JSON for data exchange, you have used JSON before, but only ......
In the development platform, the JSON format should be used as follows:
Code snippet 1:
The Code is as follows:
{
"Button ":[
{
"Type": "click ",
"Name": "Today's songs ",
"Key": "V1001_TODAY_MUSIC"
},
{
"Type": "click ",
"Name": "Introduction to singers ",
"Key": "V1001_TODAY_SINGER"
},
{
"Name": "menu ",
"Sub_button ":[
{
"Type": "view ",
"Name": "Search ",
"Url": "http://www.soso.com /"
},
{
"Type": "view ",
"Name": "video ",
"Url": "http://v.qq.com /"
},
{
"Type": "click ",
"Name": "like us ",
"Key": "V1001_GOOD"
}]
}]
}
Then use the json_encode () function of PHP to convert a two-dimensional array into a JSON format.
However, the converted JSON format is as follows:
Code snippet 2:
The Code is as follows:
{
"Button ":{
"1 ":{
"Type": "click ",
"Name": "Today's songs ",
"Key": "V1001_TODAY_MUSIC"
},
"2 ":{
"Type": "click ",
"Name": "Introduction to singers ",
"Key": "V1001_TODAY_SINGER"
},
"3 ":{
"Name": "menu ",
"Sub_button ":[
{
"Type": "view ",
"Name": "Search ",
"Url": "http://www.soso.com /"
},
{
"Type": "view ",
"Name": "video ",
"Url": "http://v.qq.com /"
},
{
"Type": "click ",
"Name": "like us ",
"Key": "V1001_GOOD"
}
]
}
}
}
The format is inconsistent.
You can only understand the JSON structure.
JSON has two types of data: 1. unordered object structure; 2. ordered array structure.
1. unordered object structure
Unordered object structures have different naming rules in different languages. For example, they are called dictionaries in Python and JSON objects in JS ......
In short, it is a combination of key/value pairs.
The JSON structure I just converted is a combination of unordered key/value pairs.
2. ordered array structure
An ordered array structure, that is, the structure displayed by code snippet 2.
Convert an array into JSON as an ordered array to obtain an ordered JOSN array structure.