Access json values with jQuery -


i want retrive trend values json array retrieved twitter api. require top 5 trend names.

json response

[{     "trends": [         {             "name": "#nationaltellagirlsheisbeautifulday",             "url": "http://twitter.com/search?q=%23nationaltellagirlsheisbeautifulday",             "promoted_content": null,             "query": "%23nationaltellagirlsheisbeautifulday",             "events": null         },         {             "name": "#youknowyouinthehoodwhen",             "url": "http://twitter.com/search?q=%23youknowyouinthehoodwhen",             "promoted_content": null,             "query": "%23youknowyouinthehoodwhen",             "events": null         },         {             "name": "#dünyafenerbahçelilergünükutluolsun",             "url": "http://twitter.com/search?q=%23d%c3%bcnyafenerbah%c3%a7elilerg%c3%bcn%c3%bckutluolsun",             "promoted_content": null,             "query": "%23d%c3%bcnyafenerbah%c3%a7elilerg%c3%bcn%c3%bckutluolsun",             "events": null         },         {             "name": "#indonesianteenager",             "url": "http://twitter.com/search?q=%23indonesianteenager",             "promoted_content": null,             "query": "%23indonesianteenager",             "events": null         },         {             "name": "#bpk13",             "url": "http://twitter.com/search?q=%23bpk13",             "promoted_content": null,             "query": "%23bpk13",             "events": null         },         {             "name": "haykırırımaşkımısana beŞİktaŞdiye",             "url": "http://twitter.com/search?q=%22hayk%c4%b1r%c4%b1r%c4%b1ma%c5%9fk%c4%b1m%c4%b1sana+be%c5%9e%c4%b0kta%c5%9ediye%22",             "promoted_content": null,             "query": "%22hayk%c4%b1r%c4%b1r%c4%b1ma%c5%9fk%c4%b1m%c4%b1sana+be%c5%9e%c4%b0kta%c5%9ediye%22",             "events": null         },         {             "name": "vogue korea",             "url": "http://twitter.com/search?q=%22vogue+korea%22",             "promoted_content": null,             "query": "%22vogue+korea%22",             "events": null         },         {             "name": "png",             "url": "http://twitter.com/search?q=png",             "promoted_content": null,             "query": "png",             "events": null         },         {             "name": "makueni",             "url": "http://twitter.com/search?q=makueni",             "promoted_content": null,             "query": "makueni",             "events": null         },         {             "name": "jeremy kyle",             "url": "http://twitter.com/search?q=%22jeremy+kyle%22",             "promoted_content": null,             "query": "%22jeremy+kyle%22",             "events": null         }     ],     "as_of": "2013-07-19t09:23:13z",     "created_at": "2013-07-19t09:14:10z",     "locations": [         {             "name": "worldwide",             "woeid": 1         }     ] }] 

jquery code

 $.getjson("url",function(data){    console.log(data); }); 

how can retrieve values object in success function?

the twitter api sends object containing trend data.

so each trend name below:

for(var = 0; < data[0].trends.length; i++) {    console.log(data[0].trends[i].name); } 

this log trend names out. hope helps


Comments