简体   繁体   English

Java中的高效JSON搜索

[英]Efficient JSON search in Java

Good Day! 美好的一天! In Java, is there any way to search a large JSON by keys efficiently. 在Java中,有没有办法有效地通过键搜索大型JSON。

My Sample JSON: 我的样本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. 'my_data'JsonArray非常冗长。 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. 快速json解析器是Jackson Java JSON处理器 ,但它必须按顺序读取整个String以找到您的值。 So if you need something faster you probably must save your data in another format than JSON, you will need some sort of index. 因此,如果您需要更快的速度,您可能必须以JSON之外的其他格式保存数据,您需要某种索引。 (But it depends on what you want to do and how fast it must be ...) (但这取决于你想做什么以及它必须有多快......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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