[英]Parsing XML array using Jquery
我一直堅持使用Jquery傳遞XML的問題。 我在遍歷jquery時得到空數組。請幫我如何從XML數組中獲取數據。 我在下面提到了我的代碼。
XML
<?xml version="1.0" encoding="UTF-8"?>
<json>
<json>
<CustomerName>999GIZA MID INSURANCEAND SERVICES PVT LTD</CustomerName>
<mobiLastReceiptDate>null</mobiLastReceiptDate>
</json>
<json>
<CustomerName>A SHRIVENGATESH</CustomerName>
<mobiLastReceiptDate>null</mobiLastReceiptDate>
</json>
<json>
<CustomerName>A 1 PROCESS</CustomerName>
<mobiLastReceiptDate>null</mobiLastReceiptDate>
</json>
<json>
<CustomerName>A A A ENTERPRISES</CustomerName>
<mobiLastReceiptDate>null</mobiLastReceiptDate>
</json>
<json>
<CustomerName>A ALAGUSUNDARAM</CustomerName>
<mobiLastReceiptDate>null</mobiLastReceiptDate>
</json>
</json>
jQuery的
page_response=getResponse("yyyURL");
page_response.success(function(data){
console.log(data.results[0]);
console.log($( data ).find( "CustomerName" ));
$(data).find("json").each(function(i, item) {
var heures = $(item).attr("CustomerName");
var nbr = $(item).attr("EMI");
<!--- Am getting array.. ineed to get name and EMI-->
console.log(heures);
});
});
您使用了錯誤的方法來獲取節點,xml元素的基礎是“節點具有屬性”。 因此,如果要在XML元素中查找任何節點,可以使用jquery.find(),但是當您想要查找某個節點的任何屬性時,可以使用jquery.attr()函數。
此外,jquery.val()和jQuery.text()是分別用於獲取元素的值和文本的函數。
希望這會有所幫助!!
干杯!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.