我使用这段代码从 GitHub API 获取数据
var name;
var description;
var html_url;
var username = "PirateStef";
var updated_at;
var language;
var repo;
var urlGitHub = 'https://api.github.com/users/'+username+'/repos?sort=created';
$.getJSON(urlGitHub, function(json){
repositories = json;
outputGitHubContent(); // GitHub Content
});
function outputGitHubContent() {
$.each(repositories, function(index){
name = "<div class='name'>" + repositories[index].name + "</div>";
description = "<div class='description'>" + repositories[index].description + "</div>";
updated_at = "<div class='updated_at'>" + repositories[index].updated_at.substring(0,10) + "</div>";
html_url = "<a class='html_url' target='_blank' href='" + repositories[index].html_url + "'>";
language = "<div class='language'>" + repositories[index].language + "</div>";
repo = "<div class='repo'>" + html_url + "<div>" + name + language + "</div>" + description + updated_at + "</a> </div>";
console.log(repositories[index].owner.login);
$("#github").append(repo);
});
};
这是 Github API 网址
https://api.github.com/users/PirateStef/repos?sort=updated
我尝试构建一个函数来获取运球数据。使用下面的 api.dribbble url。
http://api.dribbble.com/players/PirateStef/shots/
我无法从每个对象中获取“标题”。
无效的运球代码
var urlDribbble = 'http://api.dribbble.com/players/'+username+'/shots/';
var shot;
$.getJSON(urlDribbble, function(json){
shots = json;
outputDribbbleContent(); // Dribbble Content
});
function outputDribbbleContent() {
$.each(shots, function(index){
console.log(shots[index].title);
});
};
让我 5x 未定义
console.log(shots[index]);
给我这个
[
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
,
Object
]