I’m trying to alert id and subcategory in JSON string returned from the server using jQuery.
I get the following JSON string.
[{"name":"Technology","id":117,"subcategory":"Machines"},
{"name":"Technology","id":118,"subcategory":"Tools"},
{"name":"Technology","id":119,"subcategory":"Air"}]
I try to do:
$.getJSON("scene/getSubCategories/Technology",
{
format: "json"
},
function(data) {
alert(data);
$.each(data.object, function(i,object){
alert(object.id + " " +object.subcategory);
});
});
I’m getting the error
Message: ‘length’ is null or not an object
Line: 12
Char: 7740
Code: 0
URI: http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
What am I doing wrong?
I’m using jQuery 1.3.2, because I have a third-party JavaScript plugin which works with this jQuery version, and I can’t figure how both (1.3.2 and 1.4.3) versions of jQuery can live together on the same side.
Try this:
The first argument of
each()has to be the object to iterate over. It has to be data (data has no property “object”). The second argument of the provided function will be the current item of the iterated object.