2016-07-19 50 views
0

我正在將我的數據從外部文件存儲到localhost中的mongodb。這是相當龐大的數據集,容量爲1.70GB,含有約1000萬條推文。雖然從文件導入到mongodb它顯示我的錯誤「JSON讀者期待一個名字,但發現':'' 我dint以前的文件有任何錯誤。但是,我無法弄清楚。這些數據只是來自JSON格式的流API的tweets實時集合。JSON閱讀器期待一個名字,但發現':'。在Mongodb Java

BufferedReader br = new BufferedReader(new FileReader(file)); 
    int counter = 0; 
    String line; 

    while ((line = br.readLine()) != null) { 
     System.out.println(line); 
     Document old_status = Document.parse(line); 
// If it is a deleted tweet, then continue 
    if (old_status.containsKey("delete")) { 
     continue; 
    } 
    //populate original tweets  
    Document original_status = new Document(); 
    if(line.contains("retweeted_status")){ 
    Document retweets = (Document)old_status.get("retweeted_status"); 
     original_status.append("status",retweets.get("text")); 
     original_status.append("Likes",retweets.getInteger("favorite_count"));}} 

它的一個示例代碼,用於從文件導入數據到mongo集合。 幫我解決這個問題。我真的停留在這個地方,需要我的時間。 在此先感謝。

+0

看來它不能從你的文件中解析出一行。添加日誌記錄以查看哪條線路導致問題。 –

+0

@ Andriy Simonov- Json格式的錯誤。柯里括號不翼而飛。當json格式不正確時,我想要跳過什麼? – prabhu

回答

0

晚會還有一點與這個具體問題無關,但谷歌把我帶到了這裏,所以要留下一個答案。

當我試圖解析在Scala中轉換爲JSON的mongodb文檔時,出現此錯誤。確保你正在解析的變量實際上是在解析的JSON中,如果它是嚴格的解析。