How to use jQuery .each() - I get a value, but it's the wrong one
- by Ankur
I am returning a JSON object (as a String) through a servlet. The JSON object looks like this:
{"3":"Martin Luther","30":"Boris Becker","32":"Joseph Goebels","19":"Leonardo Da Vinci","31":"Adolf Hitler"}
My jQuery looks like this (the submission of data is correct because I get a proper looking result from the servlet):
$.ajax( {
type : "GET",
url : "MyServlet",
data : queryString + "count=" + variables,
success : function(resultObj) {
$.each(resultObj, function(key, value) {
$("#resultCount").html(key+", "+value);
});
}
});
However when I try to print the results, that is the variables key and value, I get a number for the key but not a number from the JSONObject and an empty string instead of the value.
Essentially the question is about how to "extract" the information from a JSON object.