How to use jQuery .each() - I get a value, but it's the wrong one

Posted by Ankur on Stack Overflow See other posts from Stack Overflow or by Ankur
Published on 2010-03-30T07:31:26Z Indexed on 2010/03/30 7:33 UTC
Read the original article Hit count: 526

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about JSON