2012-10-02 27 views
3

我想在大JSON文件中的給定關鍵字後搜索。有人知道這個java庫嗎?用於在JSON文件中搜索文本的Java庫

+1

JSON字符串就是這樣一個字符串。所以只需使用正常的javascript能力來搜索字符串。 –

+0

試試這個https://github.com/douglascrockford/JSON-java –

+0

你有沒有研究過你自己的東西?一個文件有多大?它可以在內存中解析嗎?什麼是文件的模式?您的關鍵字是否需要在字段或值中找到?請給我們更多的信息,否則我們無法正確回答您的問題。 – Brian

回答

0

你可以找到json庫它here

+0

我在這個庫中沒有看到任何搜索功能。它只是將JSON格式轉換爲Java bean,反之亦然。 – strongmayer

1

如果你只是在尋找一個關鍵字,我不明白它是如何的JSON需要一個特殊的庫。如果您正在尋找特定於JSON的內容(如鍵或值),這隻會有所幫助。

難道你不能只是逐行掃描文件並搜索子字符串?

public static boolean find(File f, String searchString) { 
    boolean result = false; 
    Scanner in = null; 
    try { 
     in = new Scanner(new FileReader(f)); 
     while(in.hasNextLine() && !result) { 
      if (in.nextLine().contains(searchString)) 
       return true; 
     } 
    } 
    catch(IOException e) { 
     e.printStackTrace();  
    } 
    finally { 
     try { in.close() ; } catch(Exception e) { /* ignore */ } 
    } 
    return false; 
} 

http://technojeeves.com/joomla/index.php/free/109-search-for-string-in-text-file-in-java