我收到的錯誤:的JavaScript/Node.js的JSON.parse()來未定義
undefined:1
'{"completed_in":0.078,"max_id":333655176038719488,"max_id_str":"3336551760387
^
SyntaxError: Unexpected token '
at Object.parse (native)
at /home/tweets/10seconds.js:25:25
at passBackControl (/home/tweets/node_modules/oauth/lib/oauth.js:367:11)
at IncomingMessage.<anonymous> (/home/tweets/node_modules/oauth/lib/oauth.js:386:9)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:895:16
at process._tickCallback (node.js:415:13)
當從搜索API解析Twitter的API JSON。
我使用的解析此JSON的代碼是:
MongoClient.connect("mongodb://localhost:27017/db", function(err, db) {
if(err) { return console.dir(err); }
var collection = db.collection("tweets");
while(run < 200){
oa.get("http://search.twitter.com/search.json?q=morning&rpp=100&include_entities=true&result_type=mixed", access_token, access_token_secret, function(error, data) {
var theTweets = JSON.parse(sys.inspect(data));
collection.insert(theTweets, {w:1}, function(err, result) {});
console.log(run);
});
run = run + 1;
}
});
這是什麼原因?
爲什麼你'sys.inspect()'數據'?我期望'data'是JSON,所以你應該只是'JSON.parse(data)',或者它已經是一個原生的JS對象,所以你根本不需要解析它。 – 2013-05-12 18:59:24
@MattBall,heh ...幾乎相同的消息= P – plalx 2013-05-12 18:59:54