JSON-JSON Data Structure

Source: Internet
Author: User


I recently used JSON for data exchange on the development platform. I used JSON before, but it is limited ......

In the development platform, the JSON format should be used as follows:
Code snippet 1:

{"Button": [{"type": "click", "name": "Today's songs", "key": "V1001_TODAY_MUSIC" },{ "type ": "click", "name": "", "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 the json_encode () function of PHP to convert a two-dimensional array into a JSON format.
 
However, the converted JSON format is as follows:
Code snippet 2:
 

{"Button": {"1": {"type": "click", "name": "Today's songs", "key": "V1001_TODAY_MUSIC "}, "2": {"type": "click", "name": "", "key": "V1001_TODAY_SINGER"}, "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", "key": "V1001_GOOD"}] }}

 



The format is inconsistent.

You can only understand the JSON structure.
JSON has two types of data: 1. unordered object structure; 2. ordered array structure.
1. unordered object structure
Unordered object structures have different naming rules in different languages. For example, they are called dictionaries in Python and JSON objects in JS ......
In short, it is a combination of key/value pairs.
The JSON structure I just converted is a combination of unordered key/value pairs.
2. ordered array structure
An ordered array structure, that is, the structure displayed by code snippet 2.
Convert an array into JSON as an ordered array to obtain an ordered JOSN array structure.

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.