3.1.6. JSON 数据集

JSON 数据集是通过 JSON 数据生成的。可以从以下来源获取此数据:

  1. Groovy script

    用户提供的脚本应该以字符串形式返回 JSON 数据。

    例如:

    return '''
            {
              "items": [
                {
                  "name": "Java Concurrency in practice",
                  "price": 15000
                },
                {
                  "name": "Clear code",
                  "price": 13000
                },
                {
                  "name": "Scala in action",
                  "price": 12000
                }
              ]
            }
            '''
  2. URL

    报表引擎将对 URL 执行 GET HTTP 查询。

    例如:

    https://jsonplaceholder.typicode.com/users
  3. 字符串类型的参数

    必须在 Parameters and Formats 标签页中描述包含 JSON 数据的 String 类型的报表外部参数。

使用 JsonPath 查询获取 JSON 树。例如,可以使用 $.store.book[*] JsonPath 返回以下 JSON 树中的所有书籍:

{
    "store": {
    "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99,
                "isbn": "0-553-21311-3"
            }
    ],
    "bicycle": {
        "color": "red",
        "price": 19.95
    }
}
}

有关 JsonPath 表达式的更多详细信息,请参阅 http://goessner.net/articles/JsonPath/