哈哈哈

先上代码

var superagent = require('superagent');
var cheerio = require('cheerio');
var http = require('http');

var qq_url='http://m.qzone.qq.com/cgi-bin/new/get_msgb?uin=0&hostUin=*&num=10&start=10&hostword=0&essence=1&r=0.48072542040608823&iNotice=0&inCharset=utf-8&outCharset=utf-8&format=jsonp&ref=qzone&g_tk=5381'
http.get(qq_url,function(res) {
    var data = "";
    res.on('data',function(chunk) {
        data+=chunk;
        var b=data.slice(data.indexOf('(')+1,data.lastIndexOf(')'));
        console.log(b)
    })
})

这边的chunk是两个buffer,暂时还不知道怎么合并(

看到一个解决方案,大致可以解决

var superagent = require('superagent');
var cheerio = require('cheerio');
var http = require('http');

var qq_url='http://m.qzone.qq.com/cgi-bin/new/get_msgb?uin=0&hostUin=*&num=10&start=10&hostword=0&essence=1&r=0.48072542040608823&iNotice=0&inCharset=utf-8&outCharset=utf-8&format=jsonp&ref=qzone&g_tk=5381'
http.get(qq_url, function (res) {
    var data = "";
    var chunks = [];
    var size = 0;
    res.on('data', function (chunk) {
        chunks.push(chunk);
        size += chunk.length;
    });
    res.on('end', function () {
        var data = null;
        switch(chunks.length) {
            case 0: data = new Buffer(0);
                break;
            case 1: data = chunks[0];
                break;
            default:
                data = new Buffer(size);
                for (var i = 0, pos = 0, l = chunks.length; i < l; i++) {
                    var chunk = chunks[i];
                    chunk.copy(data, pos);
                    pos += chunk.length;
                }
                break;
        }
        var b=chunks.toString().slice(chunks.toString().indexOf('(')+1,chunks.toString().lastIndexOf(')'));
        console.log(JSON.parse(b))
    });
});

但是不知道原理,先贴一个地址吧朴灵




(换到ubuntu了等感觉差不多了在看看C#吧)

'function'的原型链

posted @ 2015-07-24 19:08  夏棋  阅读(162)  评论(1编辑  收藏  举报