Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript未正确解析JSON中的大量数据_Javascript_Json - Fatal编程技术网

Javascript未正确解析JSON中的大量数据

Javascript未正确解析JSON中的大量数据,javascript,json,Javascript,Json,我正在以JSON格式从Web服务器传回一个已批准的推文列表。当我转到URL时:http://localhost:8000/showtweets/?after_id=354210796420608003在我的浏览器中,我得到以下JSON: [{ "date": "2013-07-08T12:10:09", "text": "#RaspberryPi ist auf dem Weg :-)", "author_pic_url": "http://a0.twimg.com

我正在以JSON格式从Web服务器传回一个已批准的推文列表。当我转到URL时:
http://localhost:8000/showtweets/?after_id=354210796420608003
在我的浏览器中,我得到以下JSON:

   [{
    "date": "2013-07-08T12:10:09",
    "text": "#RaspberryPi ist auf dem Weg :-)",
    "author_pic_url": "http://a0.twimg.com/profile_images/1315863231/twitter_normal.jpg",
    "id": 354210796420608004,
    "author": "switol"
}]
其id为:
354210796420608004

当我从Javascript发出GET调用时,号码会发生变化:

function TweetUpdater() {
}

TweetUpdater.latest_id = 0;
TweetUpdater.undisplayed_tweets = new Array();

TweetUpdater.prototype.get_more_tweets = function () {
    // var since_id = parseFloat(TweetUpdater.get_latestlatest_id;
    // alert(since_id);
    var get_tweets_url = "/showtweets/?after_id="+TweetUpdater.latest_id;
    $.get(get_tweets_url, function (tweets) {
        if (tweets.length > 0) {

            /////////////////////////////////////////////////////////
            alert(tweets[0].id+", "+ tweets[0].text); <<<<< THIS LINE
            /////////////////////////////////////////////////////////

            TweetUpdater.latest_id = tweets[0].id;
            for (var i = 0; i < tweets.length; i++) {
                TweetUpdater.undisplayed_tweets.push(tweets[i]);
            }
        }
    }, "json");
};
函数TweetUpdater(){
}
TweetUpdater.latest_id=0;
TweetUpdater.undisplayed_tweets=新数组();
TweetUpdater.prototype.get_more_tweets=函数(){
//var-since_id=parseFloat(TweetUpdater.get_latestlatest_id;
//警报(自\u id起);
var get_tweets_url=“/showteets/?after_id=“+TweetUpdater.latest_id;
$.get(get_tweets_url,函数(tweets){
如果(tweets.length>0){
/////////////////////////////////////////////////////////

警告(tweets[0].id+“,“+tweets[0].text);不,不是很奇怪。JS将所有数字表示为双精度,随着整数的增长,在某些点上会降低精度。有关详细信息,请参阅


要解决这个问题,只需将
id
变成一个字符串——你无论如何都不会用它进行计算。但是你必须在原始的JSON中这样做,否则在
JSON.parse上就会发生精度损失。

在使用twitter API时尝试使用id\u str而不是id,它应该可以工作。见此。

JS“integers”最多为2^53=9007199254740992。您的要大得多。看这里还有javascript库,以防ID需要进行算术运算。我确保ID在从服务器传回之前已转换为字符串。这解决了问题。谢谢。