D3:如何从 Github API 拉取 JSON

D3: How to pull JSON from Github API

我正在尝试使用 github API 数据进行可视化,但似乎无法将其拉出。从文档中我认为下面的行可以工作,但是当我 运行 它时没有任何内容打印到控制台。我是不是漏了什么

d3.json("https://api.github.com/search/users?q=ronanmacf", 
function(data) {
console.log(data[0]);
});

它有效,但是,在这种情况下,服务器响应是一个对象,而不是一个数组,所以你得到 undefinedconsole.log(data[0])。如果像这样 console.log(data) 更改它,您将在控制台中看到 github 用户数据。 运行 下面的代码片段:

d3.json("https://api.github.com/search/users?q=ronanmacf", 
function(data) {
console.log(data);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.12.0/d3.min.js"></script>

jQuery中我们也用console.log(data)代替了console.log(data[0])

$.getJSON( "https://api.github.com/search/users?q=ronanmacf", function( data ) {
  console.log(data);
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>