好的,我花了最后一天的时间试图弄清楚一些事情,我对编码是相对的新手,所以如果弄得一团糟,我很抱歉。我目前正在开发一个请求JSON的机器人,以下是我到目前为止拥有的代码
const request = require('request');
const bodyParser = require('body-parser');
global.count = 10;
for (var i = 1; global.count === 10; i++) {
var options = {
url: 'https://www.the100.io/api/v1/groups/2127/users?page=' + i, //Returns 10 entries per page, so loop is to navigate pages
headers: {
'Authorization': 'Token token="Hidden for Privacy"'
}
}
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body); //Also need a way to append to info as to add on as the loop progresses, still need to look that up though
console.log(JSON.stringify(info, null, 1)); //Logs the body
global.count = info.length; //Will return the value 10, until there are no more entries and then will terminate loop
}
}
request(options, callback);//Sends request
}
//It just keeps running the loop and doesn't execute the request at the bottom which is what will make the loop terminate, I've tried many things with
//callbacks and nothing has worked so far我似乎无法让循环正常运行,我不想寻求帮助,但我很遗憾地说,我被卡住了。提前谢谢你。
发布于 2016-11-07 13:11:57
我觉得有些困惑的问题和解释清楚了吗?
在你的写作中,for循环是不断重复的,你想要的是其他的东西..
在我看来,它应该是用于页面加载的导航(每个页面包含10个)
global.count = 10;
for( var i = 1; i< =global.count; i++)
{
-- Write Your code here ---
}https://stackoverflow.com/questions/40458085
复制相似问题