我试图从Topsy(http://code.google.com/p/otterapi/)获得分页的json响应,并且遇到合并对象的问题。我想在浏览器中这样做,因为api速率限制是每个ip /用户,并且低到可以做服务器端的事情。使用JavaScript合并JSON api响应
这是我的代码。有没有更好的办法?当然,这是因为这不起作用。我想我想让这个工作,但也要了解是否有一个更安全,和/或更有效的方式。
该错误消息我得到的是...
类型错误:表达式“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&[email protected]' + 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&[email protected]' + 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);
}
}
谢谢埃德加。我现在得到一个不同的错误。我想我仍然相当困惑之间的数组,和JSON对象等... ReferenceError:无法找到变量:ARRAY – 2011-04-28 08:17:37
不客气。嗯..它是否直接说“ARRAY”? PS:如果你认为它有用,请提高我的答案。谢谢 – 2011-04-28 08:22:21
我已经提出了答案,但实际上并没有解决它。是的,这是我现在得到的错误消息。欢呼 – 2011-04-28 08:27:15