I need to detect if a post contains a specific category from a JSONP feed. I'm not sure how to read the array as it's currently saying it's null. The link works without any problems though, which is just a string.
$.jsonp({
url : "theurl",
dataType : "jsonp",
timeout : 10000,
success : myFunction,
error : myErrorFunction
});
function myFunction (data) {
$.each(data, function(i, post){
var link = post.permalink,
hasCategory = $.inArray("specialcategory", post.categories);
});
}
Here's an example of my JSON:
[
{
"id": 1,
"permalink": "http://domain.com",
"categories": [
"category1",
"specialcategory"
]
}
]
This is the error that appears in Firebug:
can't convert null to object
d()jquery.js (line 16)
a = "specialcategory"
b = undefined
[Break On This Error] (function(a,b){function ci(a){return d...a:a+"px")}}),a.jQuery=a.$=d})(window);
Any help would be greatly appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…