[英]how to parse the json url response of xignite Api using jquery
我使用xignite Api顯示銀,黃金價格,每當在json中傳遞url時,它都不會輸出任何輸出,請在以下方面給我幫助,我的代碼如下:
var dmJSON = "http://globalmetals.xignite.com/xGlobalMetals.json/GetLondonFixing?Symbol=XAU&Currency=USD";
$.getJSON( dmJSON, function(data) {
$.each(data, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.Outcome+ "</td>"+ "<td>" + f.Price + "</td>" + "</tr>";
$(tblRow).appendTo("#entrydata");
});
});
不要嘗試在$ .each中進行迭代。 試試這個:str是您返回的數據
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
var str={"Outcome":"RegistrationError","Message":"XigniteGlobalMetals: Maximum number of unregistered requests exceeded. Consider registering or subscribing to expand usage.Your request was authenticated using your IP address 112.196.34.74. Please visit http://www.xignite.com/registration-help for more information. (globalmetals.xignite.com: 20) ","Identity":"IP","Delay":0.0006475,"Name":null,"Symbol":null,"QuoteType":null,"Currency":null,"Date":null,"Time":null,"Fixing":null,"Price":0.0,"Unit":null,"Source":null};
var tblRow = "<tr>" + "<td>" + str.Outcome+ "</td>"+ "<td>" + str.Price + "</td>" + "</tr>";
$('#testTable').append(tblRow);
});
</script>
<table id='testTable'>
<tr>
<td>Outcome</td>
<td>Price</td>
</tr>
</table>
這可能對您有幫助
在我的最后一個答案中,str與您問題中的數據相同,它包含從該URL返回的響應對象。
現在嘗試這個:
var dmJSON = "http://globalmetals.xignite.com/xGlobalMetals.json/GetLondonFixing?Symbol=XAU&Currency=USD";
$.getJSON( dmJSON, function(data) {
var tblRow = "<tr>" + "<td>" + data.Outcome+ "</td>"+ "<td>" + data.Price + "</td>" + "</tr>";
$('#testTable').append(tblRow);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.