JSON, Jsonarray and Jsonobject

Source: Internet
Author: User

As with XML, JSON is also a data format based on plain Text. Since JSON is inherently prepared for JavaScript, the JSON data format is very simple and can be used to transmit a simple string,number,boolean, or to transfer an array, or a complex object.

The basic structure of JSON is to use "{}" to wrap an object that contains a key and value separated by a colon, a comma delimited between Key-value pairs, a string to be wrapped in double quotation marks (""), and the Object's key name is always a string, and the property value enables any json-supported data type, including string, Other object types, numbers, and Boolean types (true or false), a specified null value, and an array. The JSON array is wrapped by "[]", the type of the array element can be any JSON data type (including objects and arrays), and the array elements are separated by ",".

{"total": 3,"rows":[   {   "userId": 1,   "realname": "zhang mei",   "headurl": "href= ' teacherdetail.html '",   "img": "src= ' images/teacher.jpg '",   "introduction": "warm and generous." "   },{   "userId": 2,   "realname": "zhang san",   "headurl": "href= ' teacherdetail.html '",   "img": "src= ' images/teacher.jpg '",   "introduction": "warm and generous." "   },{   "userId": 3,   "realname": "reese",   "headurl": "href= ' teacherdetail.html '",   "img": "src= ' images/teacher.jpg '",   "introduction": "warm and generous"   }]}

The $.getjson () method function in jquery is primarily used to load json-encoded data from the server, which uses a get HTTP Request. Here's How to use It:

$.getjson (url,[data], [success (data, textstatus, jqxhr)])

The URL is a required parameter that represents the address of the JSON data;
Data is an optional parameter that is used to send parameters when data is requested;
Success is a parameter, which is a callback function that is used to process the requested Data.

Get JSON data for example:

$.getjson (' Test.json ', function (data) {   for(var i = 0; i < data.rows.length; i++) {      $ ( /c4> ' #test '). append (' <p> ' + data.rows[i].realname + ' </p> ');}   );
Jsonobject and Jsonarray
The difference is that Jsonobject is a {} wrapped object,
The Jsonarray is an array of [] Packages.
The white point is an array, an object or a string.
JSONOBJEC has a key name, Jsonarray Not.

JSON, jsonarray, and Jsonobject

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.