views:

223

answers:

2

Hi, I am using $.getJSON(url,data,callback) method.

and from url it returns a JSON object of list type (e.g. states.ToList()) so how can i read that object?

states.ToList will have records of ID, and Name,

and I want to bind it with select tag (for selection list at client page.

A: 

Loop! valueArray <= states.ToList()

for(var i=0; i<valueArray.length; i++){
  //do something by accessing valueArray[i];
}
Martin K.
How? can you explain it with $.getJSON() code?
Vikas
+2  A: 
    $.getJSON(url,
        null,
        function(data) {
            for (i in data) {
                var state = data[i];
                // do something with state
            }
        }
    });

If you try this and it does not work, then you are either not returning an array, or you have not specified the names correctly. Look at the Net/XHR panel in Firebug to see the real shape of your data.

Craig Stuntz