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