How much do you know about JSON - JSON data structure_PHP tutorial

WBOY
Release: 2016-07-13 10:29:37
Original
853 people have browsed it


Recently when developing the WeChat platform, JSON needs to be used for data exchange. JSON has been used before, but only...

When developing the WeChat platform, the JSON format should be used as follows:
Code snippet 1:

<span> {
     </span>"button":<span>[
     {    
          </span>"type":"click",
          "name":"今日歌曲",
          "key":"V1001_TODAY_MUSIC"<span>
      }</span>,<span>
      {
           </span>"type":"click",
           "name":"歌手简介",
           "key":"V1001_TODAY_SINGER"<span>
      }</span>,<span>
      {
           </span>"name":"菜单",
           "sub_button":<span>[
           {    
               </span>"type":"view",
               "name":"搜索",
               "url":"http://www.soso.com/"<span>
            }</span>,<span>
            {
               </span>"type":"view",
               "name":"视频",
               "url":"http://v.qq.com/"<span>
            }</span>,<span>
            {
               </span>"type":"click",
               "name":"赞一下我们",
               "key":"V1001_GOOD"<span>
            }]
       }]
 }</span>
Copy after login



Then use PHP’s json_encode() function to convert the one-dimensional array into JSON form

But the converted JSON form:
Code snippet 2:

<span>{
    </span>"button":<span> {
        </span>"1":<span> {
            </span>"type": "click",
            "name": "今日歌曲",
            "key": "V1001_TODAY_MUSIC"<span>
        }</span>,
        "2":<span> {
            </span>"type": "click",
            "name": "歌手简介",
            "key": "V1001_TODAY_SINGER"<span>
        }</span>,
        "3":<span> {
            </span>"name": "菜单",
            "sub_button":<span> [
                {
                    </span>"type": "view",
                    "name": "搜索",
                    "url": "http://www.soso.com/"<span>
                }</span>,<span>
                {
                    </span>"type": "view",
                    "name": "视频",
                    "url": "http://v.qq.com/"<span>
                }</span>,<span>
                {
                    </span>"type": "click",
                    "name": "赞一下我们",
                    "key": "V1001_GOOD"<span>
                }
            ]
        }
    }
}</span>
Copy after login



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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/771650.htmlTechArticleRecently, I am developing the WeChat platform and need to use JSON for data exchange. I have used JSON before, but only when developing WeChat. In the platform, the JSON format should be used as follows: Code snippet 1: { "button":...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!