如何使用jQuery从JSON获取属性值 [英] How to get values of attributes from JSON using jQuery
本文介绍了如何使用jQuery从JSON获取属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Newtonsoft dll从xml文件生成json.从下面如何将地址详细信息放入列表(如果示例中还有更多信息)并将其写到下拉列表中,则我具有以下有效的json(已选中onjsonlint):
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 to a dropdown list I have the following valid json (checked onjsonlint):
{
"?xml": {
"@version": "1.0",
"@encoding": "utf-8"
},
"Root": {
"Information": {
"Error": {
"ErrorNo": "0",
"ErrorMsg": null
},
"Address": {
"Address": [
{
"@AddressID": "14961943",
"@Sequence": "1",
"@Description": "Some Company Name, Some Building, 10 Some Street, Some County, Some City"
}
]
}
}
}
}
推荐答案
尝试一下:
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);
}
这篇关于如何使用jQuery从JSON获取属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文