How to get values of attributes from JSON using jQuery

后端 未结 2 1675
误落风尘
误落风尘 2021-01-23 04:57

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

2条回答
  •  清歌不尽
    2021-01-23 05:10

    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);
    }
    

提交回复
热议问题