这是我目前正在学习nodejs的一系列教程。我想在 developer.github.com 上访问用户的存储库信息。当我尝试使用以下代码时,它显示错误:
json.forEach(function(repo){ ^ TypeError: Object # has no method 'forEach'
var https=require("https");
var username= "OllieParsley";
var options={
host: "api.github.com",
path: "/users/" +username+ "/repos",
method: "GET",
/*customHeaders: { "User-Agent": "app" }*/
};
var request= https.request(options, function(response){
var body='';
response.on("data", function(chunk){
body+=chunk.toString("utf8");
});
response.on("end", function(){
var repos=[];
var json=JSON.parse(body);
json.forEach(function(repo){
repos.push({
name:repo.name,
description:repo.descripton
});
});
console.log("Repos: ", repos);
});
});
request.end();
任何指针为什么错误说对象没有方法'forEach'?