我能夠從Twitter獲取JSON流到客戶端使用此代碼:解析JSON值
var command = 'curl -d @tracking https://stream.twitter.com/1/statuses/filter.json -uUsername:Password'
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
child = exec(command);
child.stdout.on('data', function(data) {
res.write(data);
});
}).listen(1337, "127.0.0.1");
,但我不能讓「文本」或' ID'值來自JSON。我已經使用jQuery的parsJSON(),和其他的東西嘗試如這樣的代碼:
var command = 'curl -d @tracking https://stream.twitter.com/1/statuses/filter.json -uUsername:password'
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
child = exec(command);
child.stdout.on('data', function(data) {
for (i=0; i<data.length; i++) {
reduceJSON = data[i]["text"]
stringJSON = String(reduceJSON)
res.write(stringJSON);
}
});
}).listen(1337, "127.0.0.1");
我不斷收到「未定義」或「readyStatesetRequestHeadergetAllResponseHeadersgetResponseHeader」或流「的對象:對象」。任何人都知道如何獲得個人價值觀?
爲什麼使用CURL和exec代替節點請求庫? – loganfsmyth 2012-02-26 01:45:35