2015-12-05 19 views
0
> orioles.tweets <- searchTwitter('#orioles', n=15, lang="en") 
> orioles.text=laply(orioles.tweets,function(t) t$getText()) 
> class(toJSON(orioles.text)) 
[1] "character" 

爲什麼會發生這種情況?試圖將推文轉換爲json格式以插入到mongoDB中

+1

你還沒有解釋這個結果是什麼意外。 –

+0

toJSON()必須將推文轉換爲json格式。所以類(toJSON(orioles.text))應該給我結果「json」 – VBB

回答

0

目前還不清楚爲什麼你會認爲該類應該是「json」。據推測,您正在使用具有toJSON功能的R軟件包之一。選擇rjsom包作爲測試用例,我發現,在?toJSON - 幫助頁面的第一個例子給出了「性格」作爲類的retruned對象:

> ??toJSON 
> library(rjson); x <- list(alpha = 1:5, beta = "Bravo", 
+   gamma = list(a=1:3, b=NULL), 
+   delta = c(TRUE, FALSE)) 
> json.vec <- toJSON(x) 
> class(json.vec) 
[1] "character" 

如果你正在從後續等待處理錯誤,因爲類設置不正確,你可以指定一個類:

class(json.vec) <- "json" 

這通常不建議,但可能需要它的情況下的JSON-扯皮庫的選擇是不一樣的一個作爲被另一選擇包作者。