简体   繁体   中英

Efficient JSON search in Java

Good Day! In Java, is there any way to search a large JSON by keys efficiently.

My Sample JSON:

{
    "my_data": [
        {
            "id": "12",
            "message": "z1",
            "text": "hai"
        },
        {
            "id": "13",
            "message": "z2",
            "text": "get"
        },
        {
            "id": "14",
            "message": "z3",
            "text": "up"
        }
    ]
}

The 'my_data' JsonArray is very lengthy. As it is very large, it takes more time to search a particular word in it as:

my_data.get(index).getString("text").contains(SEARCH_STRING)

Is there any pre-defined libraries or standard technique to search efficiently?

Thank you.

由于它是纯文本数据,您可以使用Lucene等标准文本搜索工具处理它们,并根据它找到您的条目。

Fast json parser is Jackson Java JSON-processor , but it have to read sequentially whole String to find your value. So if you need something faster you probably must save your data in another format than JSON, you will need some sort of index. (But it depends on what you want to do and how fast it must be ...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM