gpt4 book ai didi

javascript - 使用 Javascript 合并 JSON api 响应

转载 作者:行者123 更新时间:2023-12-02 20:19:15 25 4
gpt4 key购买 nike

我正在尝试从 Topsy (http://code.google.com/p/otterapi/) 获取分页 json 响应,但在合并对象时遇到问题。我想在浏览器中执行此操作,因为 api 速率限制是针对每个 ip/用户的,并且在服务器端执行操作的速率较低。

这是我的代码。有没有更好的办法?当然有,因为这是行不通的。我想我想让这个工作正常进行,但也想了解是否有更安全和/或更有效的方法。

我收到的错误消息是...

类型错误:表达式“window.holdtweetslist.prototype”的结果[未定义]不是对象。

提前致谢。

干杯斯蒂芬

    $("#gettweets").live('click', function(event){ 

event.preventDefault();
getTweets('stephenbaugh');

});



function getTweets(name) {

var MAX_TWEETS = 500;
var TWEETSPERPAGE = 50;
var BASE = 'http://otter.topsy.com/search.json?type=tweet&perpage=' + TWEETSPERPAGE + '&window=a&nohidden=0&q=@' + name + '&page=1';

var currentpage = 1;
alert(BASE);

$.ajax({
dataType: "json",
url: BASE,
success: function(data) {

window.responcesreceived = 1;
var response=data.response;
alert(response.total);
window.totalweets = response.total;

window.pagestoget = Math.ceil(window.totalweets/window.TWEETSPERPAGE);

window.holdtweetslist = response.list;

window.holdtweetslist.prototype.Merge = (function (ob) {var o = this;var i = 0;for (var z in ob) {if (ob.hasOwnProperty(z)) {o[z] = ob[z];}}return o;});

// alert(data);
;; gotTweets(data);

var loopcounter = 1;
do
{
currentpage = currentpage + 1;
pausecomp(1500);
var BASE = 'http://otter.topsy.com/search.json?type=tweet&perpage=' + TWEETSPERPAGE + '&window=a&nohidden=0&q=@' + name + '&page=' + currentpage;
alert(BASE);
$.ajax({dataType: "json", url: BASE, success: gotTweets(data)});
}
while (currentpage<pagestoget);

}
});
};

function gotTweets(data)
{
window.responcesreceived = window.responcesreceived + 1;
var response = data.response;
alert(response.total);
window.holdtweetslist.Merge(response.list);
window.tweetsfound = window.tweetsfound + response.total;
if (window.responcesreceived == window.pagestoget) {
// sendforprocessingsendtweetlist();
alert(window.tweetsfound);
}
}

最佳答案

您将 Merge 作为静态方法调用,但将其声明为“实例”方法(针对 prototype 保留字)。

从 Merge 声明中删除 prototype,这样您将拥有:

window.holdtweetslist.Merge = (function(ob)...

这将修复 JavaScript 错误。

关于javascript - 使用 Javascript 合并 JSON api 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5815429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com