I have two types of JSON results:
{ "person":{ "fname": "Homer", "lname": "Simpson" } } { "person":[ { "fname": "Homer", "lname": "Simpson" }, { "fname": "Marge", "lname": "Simpson" } ] }
I want to use jQuery "every":
$.each(response.person, function(i, person){...
but "i" and "person" are different when JSON has one or more people. I see that the response of one person does not have an array [], but when I:
$.each([response.person], function(i, person){...
then a few people do not work. I am looking for a way to normalize things so that I can consistently use "everyone."
source share