JSON knows how many-json data structures _php Tutorials

Source: Internet
Author: User
Recently in the development platform, to use JSON for data exchange, previously used JSON, but limited to ...

In the development platform, you will use the following JSON form:
Code Snippet 1:

{     "button":[     {              "type": "Click",          "name": "Today's song",          "key": "V1001_today_music"       },      {           "type": "Click",           "name": "Singer Profile",           "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 PHP's Json_encode () function to convert the one or two-D array into JSON form

But the converted JSON form:
Code Snippet 2:

  { "button":  { "1":  { "type": "Click", "Name": "Today's Song", "Key": "V1001_today_music" } , "2":  { "t Ype ":" click "," Name ":" Singer Profile "," Key ":" V1001_today_singer "} ," 3 ":  { "name": "Menu", "Sub_button":  [{ "type": "Vie                 W "," Name ":" Search "," url ":" http://www.soso.com/"} ,  { "type": "View", "Name": "Video", "url": "HT                    tp://v.qq.com/"} ,  {" type ":" Click ", "Name": "Like Us", "Key": "V1001_good" }]}}}



It is inconsistent to see the form.

Just look at the structure of the JSON.
JSON has two kinds of data: 1. Unordered object structure; 2. Ordered array structure
1. Unordered object structure
Unordered object structures are called differently in different languages, such as in Python, called a dictionary, and in JS called JSON objects ...
In short, the key/value pairs are combined form.
The JSON structure I switched out just now is an unordered combination of key/value pairs
2. Ordered array structure
An ordered array structure, which is the structure shown in code Snippet 2.
By converting the array to JSON as an ordered array, you can get an ordered JOSN array structure.

http://www.bkjia.com/PHPjc/771650.html www.bkjia.com true http://www.bkjia.com/PHPjc/771650.html techarticle recently in the development platform, to use JSON for data exchange, previously used JSON, but only in the development platform, to use the JSON form as follows: Code Snippet 1: {"button": ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.