These days handling json object is very essential in all kinds of applications , this post would help you to do that in very easy way .There are many way to handle json and some of them are described bellow .My aim is to help around the newbees here in json and javascript .
following code snippet will help you to call a remote end point and loop through the response json using jquery
Using Jquery
$.getJSON(requestURL, {
'apikey' : apiKey,
if (data.results && data.results.length > 0) {
$.each(data.results, function(i, rep) {
// do looping stuff here - i=index and rep is value
});
} else {
// else part
}
});
'zip' : zipcode,
}, function(data){
in pure java script we can loop through json object in two ways. If we are not concern about the order in which loop through we can go for a for each loop . Some other situations we must need to keep the order or we mus loop in sequential order in that case we must use standard for loop as given bellow
var info = {
"full_name" : "sudeep cv",
"title" : "Java developer",
"links" : {
"blog" : "http://iviewsource.com",
"facebook" : "https://www.facebook.com/sudeepcv90",
"twitter" : "https://twitter.com/sudeepcv",
"github" : "https://github.com/sudeepcv",
"web" : "http://sudeep-cv.tk/"
}
};
var output = "";
for ( key in info.links ) {
if (info.links.hasOwnProperty(key)) {
console.log( info.links[key] );
} //if the links has the key property
} // for...go through each link
or
for (var i = 0; i <= info.links.length; i++) {
for (key in info.links[i]) {
if (info.links[i].hasOwnProperty(key)) {
console.log( info.links[i][key] );
} // hasOwnProperty check
} // for each object
} //for each array element
following code snippet will help you to call a remote end point and loop through the response json using jquery
Using Jquery
$.getJSON(requestURL, {
'apikey' : apiKey,
if (data.results && data.results.length > 0) {
$.each(data.results, function(i, rep) {
// do looping stuff here - i=index and rep is value
});
} else {
// else part
}
});
'zip' : zipcode,
}, function(data){
in pure java script we can loop through json object in two ways. If we are not concern about the order in which loop through we can go for a for each loop . Some other situations we must need to keep the order or we mus loop in sequential order in that case we must use standard for loop as given bellow
var info = {
"full_name" : "sudeep cv",
"title" : "Java developer",
"links" : {
"blog" : "http://iviewsource.com",
"facebook" : "https://www.facebook.com/sudeepcv90",
"twitter" : "https://twitter.com/sudeepcv",
"github" : "https://github.com/sudeepcv",
"web" : "http://sudeep-cv.tk/"
}
};
var output = "";
for ( key in info.links ) {
if (info.links.hasOwnProperty(key)) {
console.log( info.links[key] );
} //if the links has the key property
} // for...go through each link
or
for (var i = 0; i <= info.links.length; i++) {
for (key in info.links[i]) {
if (info.links[i].hasOwnProperty(key)) {
console.log( info.links[i][key] );
} // hasOwnProperty check
} // for each object
} //for each array element
nice blog
ReplyDeletewebsite application developer
ReplyDeleteEverything is fine, am happy about your blog. Thanks admin for sharing the unique content, you have done a great job I appreciate your effort and I hope you will get more positive comments from the web users.
ReplyDeleteRegards,
Camellia
SAP Training in Chennai
Another great information,excellent way for this one.coding easily understand and develop more skills after refer that post,thanks for sharing this post.
ReplyDeletehtml5 training in chennai
Wow amazing i saw the article with execution models you had posted. It was such informative. Really its a wonderful article. Thank you for sharing and please keep update like this type of article because i want to learn more relevant to this topic.
ReplyDeletedigital marketing training Chennai
this is really too useful and have more ideas from yours. keep sharing many techniques. eagerly waiting for your new blog and useful information. keep doing more.
ReplyDeleteDigital Marketing Company in Chennai
Digital Marketing Services in Chennai
Your content is awesome . You have done a great job and its very useful for me . I appreciate your effort and I hope that you will get more positive comments from the web users.
ReplyDeleteBranding Services in Chennai
ReplyDeletelooping through json objects nice posts..
sap netweaver training in hyderabad
This comment has been removed by the author.
ReplyDeletethanks for publishing this programming i getting idea,
ReplyDeleteBack to original
Thank you for sharing the information here. Its much informative and really i got some valid information. You had posted the amazing article.
ReplyDeleteDataware Housing Training in Chennai
Interesting blog JSON objects which attracted me more.Spend a worthful time.keep updating more.
ReplyDeleteDigital marketing company in Chennai
wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much
ReplyDeleteSelf Employment Tax
Tax Preparation Services
Tax Accountant
Tax Consultant
Tax Advisor
This comment has been removed by the author.
ReplyDelete