Basic knowledge of JSON data structure from scratch

Source: Internet
Author: User
This article mainly introduces the knowledge of JSON data structures. For more information about JSON data structures, see the recently developed platform. If you want to use JSON for data exchange, you have used JSON before, but only ......

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

The Code is as follows:


{
"Button ":[
{
"Type": "click ",
"Name": "Today's songs ",
"Key": "V1001_TODAY_MUSIC"
},
{
"Type": "click ",
"Name": "Introduction to singers ",
"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:

The Code is as follows:


{
"Button ":{
"1 ":{
"Type": "click ",
"Name": "Today's songs ",
"Key": "V1001_TODAY_MUSIC"
},
"2 ":{
"Type": "click ",
"Name": "Introduction to singers ",
"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.