gpt4 book ai didi

java - 找出与给定行号匹配的信息的最佳方法是什么

转载 作者:行者123 更新时间:2023-12-02 00:28:14 25 4
gpt4 key购买 nike

我有一个 JSON,里面有很多数组。我需要从中提取信息的最佳方法。问题是需要最好的方法来做到这一点,否则我的建议必须等待很多时间才能给出输出。有没有一种好方法可以做到这一点,而无需对每个 JSON 数组进行迭代。我附上了我收到的示例 JSON 数据集。

  "program": [
{
"sourceElements": [
{
"sourceElement": [
{
"statement": []
}
]
},
{
"sourceElement": [
{
"statement": [
{
"line": 1,
"column": 0,
"type": "Function",
"text": "function"
}
]
}
]
},
{
"sourceElement": [
{
"statement": [
{
"expressionStatement": [
{
"expressionSequence": [
{
"argumentsExpression": [
{
"identifierExpression": [
{
"line": 1,
"column": 9,
"type": "Identifier",
"text": "a"
}
]
},
{
"arguments": [
{
"line": 1,
"column": 11,
"type": "OpenParen",
"text": "("
},
{
"line": 1,
"column": 12,
"type": "CloseParen",
"text": ")"
}
]
}
]
}
]
},
{
"eos": []
}
]
}
]
}
]
},
{
"sourceElement": [
{
"statement": [
{
"block": [
{
"line": 1,
"column": 14,
"type": "OpenBrace",
"text": "{"
}
}

}
]
} ```

最佳答案

您可以使用Jayway JsonPath (用于读取 JSON 文档的 Java DSL。Jayway JsonPath)。

您可以使用 json-path 表达式从 JSON 中提取所需的元素。

例如:

$.store.book[*].author  The authors of all books

$..author All authors

$.store.* All things, both books and bicycles

$.store..price The price of everything

$..book[2:] Book number two from tail

$..book[?(@.isbn)] All books with an ISBN number

$.store.book[?(@.price < 10)] All books in store cheaper than 10

$..book[?(@.price <= $['expensive'])] All books in store that are not "expensive"

$..book[?(@.author =~ /.*REES/i)] All books matching regex (ignore case)

关于java - 找出与给定行号匹配的信息的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58037415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com