我正在建立一個節點表達角度twitter狀態分析器,我試圖弄清楚如何從中拉出tex並將其分配給一個長字符串供以後使用。循環通過對象數組來拉出特定的數據
我想拉用戶的狀態是這樣的:
client.get('statuses/user_timeline', {params, count:20}, function(error, tweets, response) {
var jsonObject;
if (!error) {
analyze.analyze(tweets);
}
});
響應看起來是這樣的:
[
{
"coordinates": null,
"favorited": false,
"truncated": false,
"created_at": "Wed Aug 29 17:12:58 +0000 2012",
"id_str": "240859602684612608",
"entities": {
"urls": [
{
"expanded_url": "/blog/twitter-certified-products",
"url": "",
"indices": [
52,
73
],
"display_url": "
}
],
"hashtags": [
],
"user_mentions": [
]
},
"in_reply_to_user_id_str": null,
"contributors": null,
"text": "Introducing the Twitter Certified Products Program: ",
"retweet_count": 121,
"in_reply_to_status_id_str": null,
"id": 240859602684612608,
"geo": null,
"retweeted": false,
"possibly_sensitive": false,
"in_reply_to_user_id": null,
"place": null,
"user": {
"profile_sidebar_fill_color": "DDEEF6",
"profile_sidebar_border_color": "C0DEED",
"profile_background_tile": false,
"name": "Twitter API",
"profile_image_url": ",
"created_at": "Wed May 23 06:01:13 +0000 2007",
"location": "San Francisco, CA",
"follow_request_sent": false,
"profile_link_color": "0084B4",
"is_translator": false,
"id_str": "6253282",
"entities": {
"url": {
"urls": [
{
"expanded_url": null,
"url": "",
"indices": [
0,
22
]
}
]
},
"description": {
"urls": [
]
}
},
而且我現在的代碼如下所示:
function analyze(data) {
for (var i = 0; i < data.length; i++) {
tweet = data[i]['text'];
tweet = tweet.replace('#' , '');
return console.log(tweet);
}
}
module.exports.analyze = analyze;
目前,我的分析功能只能在我的輸出中獲得一條推文。我究竟做錯了什麼?
謝謝。
響應'JSON'無效。 –
我知道這不是JSON。它看起來像是一系列物體。 – Quesofat