阅读Json(CoinWarz)时出错

时间:2017-06-09 19:24:17

标签: jquery json

我是一个非常非常新的阅读数据与JQuery,但我已经做了一些小项目。我总是以同样的方式阅读Json数据但是使用这个链接coinwarz它不起作用。任何人都知道什么是转储错误?感谢。

    jQuery.ajax({
 dataType: "json",
 url: "https://www.coinwarz.com/v1/api/coininformation/?apikey=XXXX&cointag=BTC",
 success: function( data ) {
console.log("Hi");
   for ( var member in data) {

     // Change the abbreviation to be the currancy you want
        var value = data[member]
        console.log(value);

     }
   }
});

1 个答案:

答案 0 :(得分:0)

我相信您想要阅读的是data.Data,这是您实际想要循环的数据,我不确定您要对这些数据做什么,但我建议您查看here和也许过滤器可用于检查您想要的货币here
也许你想在实际读取数据之前首先添加一个if(data.success === true)的条件

我会做的是

    success: function( data ) {
    console.log("Hi");
// if the status is ok 
if(data.Success == true){
  /// Filter function will loop through your data list and return the list containing the data meeting the condition, in this case exchange equal to the currency you want.      
  var theoneIwant = data.Data.filter(function(currency){
  return currency.Exchange === "the currancy you want";
});
}
}
// success is false, show error 
else {console.log("Error " + data.Message);}