While finding out a solution for a simple but a concerned problem that is to check weather a given JSON path will return something or the path doesn't exist. To find this out we have a solutions to tackle the situation.
By using If condition
If and else condition is used for purposes that also includes checking the JSON path. The example I'll be using here is of Facebook shares.
In on of my previous articles I shared of parsing Facebook data for a web page, If the page do not have any shares then the JSON data do not contain any shares.
Taking data as argument
if(data.shares){
var commentcount=data.shares;
}else{
var commentcount="No Shares";
}
Post A Comment:
0 comments: