Home  >  Article  >  Web Front-end  >  Learn JSON data structure from scratch_Basic knowledge

Learn JSON data structure from scratch_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:47:461208browse

Recently, I am developing the WeChat platform and need to use JSON for data exchange. I have used JSON before, but only...

In developing the WeChat platform, the JSON format to be used is as follows:
Code snippet 1:

Copy code The code is as follows :

{
"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.

Statement:
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