Hey all, I hope all are doing well. I have a goody question for ya, it isnt really a dojo question but I think I can get some help here. I have a json string:
{items:[{"id":"62","firstName":"Dd","lastName":"Dd","title":"Kljasdfsdf","userphone":"222 333 4444","phoneext":"33","degreeyear":"1900","yrscompany":"0","companyname":"44","addressone":"adsf","addresstwo":"22","state":"CT","zip":"12345","country":"Anguilla","num_eng":"0","mech_eng":"0","mech_eng_yrs_exp":"0","elec_eng":"0","elec_eng_yrs_exp":"0","soft_eng":"0","soft_eng_yrs_exp":"0","sys_eng":"0","sys_eng_yrs_exp":"0","naics_code":"0","creation":"20071213","modified":"20071214-11:43:55","serial":"4436578972312394071312"}]}And I have an ajax request that looks like this:
function addEvent() {
var URL = new Object();
URL.address = 'http://miys02ae211935l/testingOnly/test.json';
var eventsubmit = ({
url: URL.address,
content: {'p1':'WTF'},
handleAs: "json",
timeout:5000,
handle: function(response, ioArgs){
return response;
}
});
var def = dojo.xhrPost(eventsubmit);
def.addCallback('doMe');
}
function doMe(data, ioArgs)
{
console.debug(data.items[0].id);
for(var i in data.items[0]){
console.debug(i);
console.debug(data.items[0].i);
}
}So when I do console.debug(i); I get this,
id firstName lastname .......
but when I do console.debug(data.items[0].i); I get
undefined undefined undefined .......
How can I spit out what is in the object?
Thanks,
timgerr

Depending on what data you
Depending on what data you want to see and how you want it presented, you could:
With the for command/*
With the for command
for(var i in data.items[0]){ console.debug(i); console.debug(data.items[0].i); }when I do the console.debug(i) I get the
I dont want to have to explicitly give all the
I want to do loop through data.items[0].i because i has all I need. Can this be done?
Thanks,
timgerr
Try this...
var value; for(var i in data.items[0]){ value = eval("data.items[0]." + i);console.log(i + " = " + value); }or, better,
var value; for(var i in data.items[0]){ value = data.items[0][i];console.log(i + " = " + value); }Note: Javascript does not guarantee the order in which objects (attributes) are returned in a for(var i in...) loop. This may or may not be important in your application.