jquery parsing get JSON data file instance

Source: Internet
Author: User
Tags generator json

JSON is a convenient form of data, the following using the $.getjson method, to achieve the JSON data and parsing, are very convenient and simple

jquery file

The code is as follows Copy Code
$ (function () {
var url= "/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?"
Using the Getjson method to get JSON data
$.getjson (
Url
Processing data to refer to the returned JSON data
function (data) {
Generate title and header connections
var tit= "<a href=" + data.link + "' >" +data.title + "</a>";
$ ("H1"). html (tit);
Appears in H1 at the specified location
$ ("#ginfo"). Find ("P"). EQ (0). html (data.modified);
$ ("#ginfo"). Find ("P"). EQ (1). html (data.generator);
var lis= "";
Li list Items
$ (Data.items). each (function (i,ite) {
Traverse JSON data to get the desired form
lis+= "<li>";
lis+= "<a href= '" + Ite.link + "' ></></a>";
lis+= "<div>";
Lis+=ite.description;
lis+= "</div></li>";
})
$ ("ul"). html (LIS);
To present the traversed data in the desired position
$ ("Li"). Hover (function () {$ (this). addclass (' Hov ')}, function () {$ (this). Removeclass ("Hov")});
}
)
})

HTML file

The code is as follows Copy Code

<div class= "Main" >
<div class= "Ginfo" id= "Ginfo" >
<p></p>
<p></p>
</div>
<ul>
</ul>
</div>

Finally say the JSON data format, in fact it is a text file, you can easily parse, you can directly view

The code is as follows Copy Code


({
"title": "Recent uploads tagged cat",
"Link": "tags/cat/",
"description": "",
"Modified": "2009-08-03t01:50:45z",
"Generator": "http://www.flickr.com/",
"Items" {
"title": "DSC06844",
"Link": "g_bugel/3783605340/",
"Media": {"M": "/3783605340_a3cfc9eeb9_m.jpg"},
"Date_taken": "2009-07-06t07:27:59-08:00",
"description": "<p><a href="/">g.bugel</a> posted a photo:</p> <p><a href=" g_bugel/ 3783605340/"title=" DSC06844 "></a></p> ",
"Published": "2009-08-03t01:50:45z",
"Author": "Nobody@flickr.com (G.bugel)",
"author_id": "38658309@n00",
"Tags": "The Cat feline Beijing 2009 Chinalab chinalab2009"

},{......});


jquery Traversal Parse JSON object 1:

The code is as follows Copy Code
var json = [{dd: ' SB ', AA: ' Dongdong ', RE1:123},{CCCC: ' DD ', LK: ' 1QW '}];
for (Var i=0,l=json.length;i<l;i++) {
for (var key in Json[i]) {
Alert (key+ ': ' +json[i][key]);
}
}

jquery Traversal Parse JSON object 2

There are the following JSON objects:

  code is as follows copy code

var obj ={" Name ":" Feng Juan "," Password ":" 123456″, "department": "Technical department", "Sex": "female", "old": "a";

Traversal method:

for [var p in obj] {
   str = str+obj[p]+ ', ';
   return str;
}

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.