The JSON (JavaScript Object Notation) is a lightweight format for data interchange, which is a JavaScript objects notation. It is very convenient for programmers to deal with the data, but also easy for the machine to parse and generate data, the application is very extensive.
JSON files can be saved as "Test.json" files
The general format of the JSON data is as follows (for an object in "{}", an array in "[]")
{
"Total": 3,
"Rows": [
{
"UserId": 1,
"Realname": "Zhang San",
"Headurl": "Href= ' teadetail.html '",
"img": "Src= ' images/tea1.jpg '",
"Introduction": "Warm and generous." "
},{
"UserId": 2,
"Realname": "Harry",
"Headurl": "Href= ' teadetail.html '",
"img": "Src= ' images/tea2.jpg '",
"Introduction": "Warm and generous." "
},{
"UserId": 3,
"Realname": "John Doe",
"Headurl": "Href= ' teadetail.html '",
"img": "Src= ' images/tea3.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++) {
$ (' #test '). Append (' <p> ' + data.rows[i].realname + ' </p> ');
}
});
This article is from the "June Blog" blog, please be sure to keep this source http://liyujun.blog.51cto.com/1482472/1664903
Introduction to How to use $.getjson ()