I am generating json from an xml file using the Newtonsoft dll. From the below how would I get the address details into a list(if there were more in the example) and write them
Solution without use of jQuery:
var select = document.getElementById('selectID');
var addresses = json.Root.Information.Address.Address;
for(var i = 0, l = addresses.length; i < l; i++) {
var o = document.createElement('option');
o.value = addresses[i]['@AddressID'];
o.innerHTML = addresses[i]['@Description'];
select.appendChild(o);
}
Try this:
var json = // that object above
var addresses = json.Root.Information.Address.Address;
for (var i = 0; i < addresses.length; i++) {
var $option = $("<option></option>").val(addresses[i]["@AddressID"]).text(addresses[i]["@Description"]);
$("#mySelect").append($option);
}
Example fiddle