如何使用jquery解析xignite Api的json url响应

时间:2014-04-22 10:51:02

标签: jquery json api

Iam使用xignite Api显示银色,黄金率,每当在json中传递url时,它都不打印任何输出,plz帮助我这方面我的代码如下:

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

}); 

2 个答案:

答案 0 :(得分:0)

不要尝试迭代$ .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>

这可能对您有所帮助

答案 1 :(得分:0)

在我的上一个答案中,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);
       }