Reputation: 33421
I am receiving JSON from my PHP webservice like so:
{"success":false,"
errors":{"x":"y"}
}
I am trying to loop through the errors
array:
var data = Y.JSON.parse(response.responseText); //Parse the JSON above
Y.Array.each(data.errors, function(item, index){
Y.log(item); //No Log in my console
});
The problem is that the function supplied to the each
is never executed.
What am I doing wrong?
Upvotes: 1
Views: 840
Reputation: 33421
Turns out that errrors
is not an array. To be an array, it needs to be in this form:
{"success":false,"
errors":[{"x":"y"}]
}
So, in my case, I had to iterate the object like so:
Y.Object.each(data.errors, function(item, index){
});
Upvotes: 2