How to get values of attributes from JSON using jQuery

后端 未结 2 1673
误落风尘
误落风尘 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:17

    Try this:

    var json = // that object above
    var addresses = json.Root.Information.Address.Address;
    
    for (var i = 0; i < addresses.length; i++) {
        var $option = $("").val(addresses[i]["@AddressID"]).text(addresses[i]["@Description"]);
        $("#mySelect").append($option);
    }
    

    Example fiddle

提交回复
热议问题