Recently, I am developing the WeChat platform and need to use JSON for data exchange. I have used JSON before, but only...
{
"button":[
{ "type":"click",
"name":"Today's song",
" key":"V1001_TODAY_MUSIC"
},
{
"type":"click",
"name":"Singer profile",
"key":"V1001_TODAY_SING ER"
},
"name":"Search ",
"url":"http://www.soso.com/"
"name":"video ",
"url":"http://v.qq.com/"
"name":"Like Check us out",
"key":"V1001_GOOD"
Then use PHP's json_encode() function to convert the one-dimensional array into JSON form
But the converted JSON form:
Code snippet 2:
Copy code
The code is as follows:
{
"button": {
"1": {
"type": "click",
"name": "Today's song",
" Key ":" v1001_today_music "
},
" 2 ": {
" Type ":" Click ",
" name ":" Introduction to Singer ",
" Key ":" V1001_TODAY_SINGER"
"3": {
"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",
}
}
}
It can be seen that the form is inconsistent.
We can only learn about the structure of JSON.
JSON has two kinds of data: 1. Unordered object structure; 2. Ordered array structure
1. Unordered object structure
Unordered object structure has different names in different languages. For example, it is called a dictionary in Python and a JSON object in JS...
In short, it is a key/value pair combination.
The JSON structure I just converted is an unordered key/value pair combination
2. Ordered array structure An ordered array structure, which is the structure shown in code snippet 2.
Convert the array to JSON as an ordered array to get an ordered JOSN array structure.